Lazarus, PostgreSQL, "Field not found" error lazarus / 16-Databases ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 08:48 Hello; I created the database on PostgreSQL with the following script: Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i CREATE DATABASE db_test WITH OWNER u_test         TEMPLATE template0         ENCODING 'UTF-8'         LC_COLLATE 'tr_TR.UTF-8'         LC_CTYPE = 'tr_TR.UTF-8'; The table is as follows: Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i create table kullanicilar(   okytno                               serial                NOT NULL,                constraint pk__kullanicilar__okytno     primary key(okytno),      kullanici_ismi             varchar(100)    NOT NULL,                constraint uk__kullanicilar__kullanici_ismi     unique (kullanici_ismi),   faal                               boolean                 NOT NULL        DEFAULT FALSE,   olusturulma_tarihi   timestamp               NOT NULL        DEFAULT Now()); When I type the SELECT clause into the query object, it throws error like this: 'Field not found: "kullanici_ismi"' What is the reason for this? Is it possible to convert "i" in the column name to "İ"? If so, how do I prevent it? ---------------------------------------------------------------------- tr_escape · 2019-07-24 08:55 Dear Ali, Could you please create a example project about your configuration and you can upload as attachment. Also please tell us what is your OS, lazarus / fpc versions. ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 11:04 Hello. First of all, thank you for your interest. Data unit. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit dm_yp_01; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, db, pqconnection, sqldb, ZConnection, ZDataset; type   { TDataModule1 }   TDataModule1 = class(TDataModule)    DataSource9: TDataSource;    dsKullanicilar: TDataSource;    DataSource2: TDataSource;    DataSource3: TDataSource;    DataSource4: TDataSource;    DataSource5: TDataSource;    DataSource6: TDataSource;    DataSource7: TDataSource;    DataSource8: TDataSource;    PQConnection1: TPQConnection;    qKullanicilarokytno: TLongintField;    SQLQuery1: TSQLQuery;    SQLTransaction1: TSQLTransaction;    ZConnection1: TZConnection;    qKullanicilar: TZQuery;    ZQuery2: TZQuery;    ZQuery3: TZQuery;    ZQuery4: TZQuery;    ZQuery5: TZQuery;    ZQuery6: TZQuery;    ZQuery7: TZQuery;    ZQuery8: TZQuery;    procedure ZConnection1AfterConnect(Sender: TObject);  private   public   end; var  DataModule1: TDataModule1; implementation {$R *.lfm} { TDataModule1 } procedure TDataModule1.ZConnection1AfterConnect(Sender: TObject);begin end; end. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object DataModule1: TDataModule1  OldCreateOrder = False  Height = 580  HorizontalOffset = 488  VerticalOffset = 149  Width = 896  PPI = 96  object ZConnection1: TZConnection    ControlsCodePage = cCP_UTF8    AutoEncodeStrings = False    Properties.Strings = (      'AutoEncodeStrings='    )    Connected = True    AfterConnect = ZConnection1AfterConnect    HostName = 'localhost'    Port = 0    Database = 'db_test'    User = 'u_test'    Password = 'şifrem'    Protocol = 'postgresql'    left = 56    top = 40  end  object qKullanicilar: TZQuery    Connection = ZConnection1    SQL.Strings = (      'SELECT *'      'FROM kullanicilar'    )    Params = <>    left = 56    top = 424    object qKullanicilarokytno: TLongintField      FieldKind = fkData      FieldName = 'okytno'      Index = 0      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = True    end  end  object dsKullanicilar: TDataSource    DataSet = qKullanicilar    left = 56  top = 496  end  object ZQuery2: TZQuery    Connection = ZConnection1  Params = <>    left = 160    top = 424  end  object DataSource2: TDataSource    DataSet = ZQuery2    left = 160    top = 496  end  object ZQuery3: TZQuery    Connection = ZConnection1    Params = <>  left = 248    top = 424  end  object DataSource3: TDataSource    DataSet = ZQuery3    left = 248    top = 496  end  object ZQuery4: TZQuery    Connection = ZConnection1    Params = <>    left = 352    top = 424  end  object DataSource4: TDataSource    DataSet = ZQuery4  left = 352    top = 496  end  object ZQuery5: TZQuery    Connection = ZConnection1    Params = <>    left = 456    top = 424  end  object DataSource5: TDataSource    DataSet = ZQuery5    left = 456    top = 496  end  object ZQuery6: TZQuery    Connection = ZConnection1    Params = <>    left = 560    top = 424  end  object DataSource6: TDataSource    DataSet = ZQuery6    left = 560    top = 496  end  object ZQuery7: TZQuery    Connection = ZConnection1    Params = <>  left = 648    top = 424  end  object DataSource7: TDataSource    DataSet = ZQuery7    left = 648    top = 496  end  object ZQuery8: TZQuery    Connection = ZConnection1    Params = <>    left = 752    top = 424  end  object DataSource8: TDataSource    DataSet = ZQuery8  left = 752    top = 496  end  object PQConnection1: TPQConnection    Connected = True    LoginPrompt = False    DatabaseName = 'db_test'  KeepConnection = False    Password = 'şifrem'    Transaction = SQLTransaction1    UserName = 'u_test'    CharSet = 'tr_TR.UTF-8'    HostName = 'localhost'    left = 248    top = 40  end  object SQLQuery1: TSQLQuery    IndexName = 'DEFAULT_ORDER'    FieldDefs = <        item        Name = 'okytno'        DataType = ftInteger        Precision = -1      end          item        Name = 'kullanici_ismi'      DataType = ftString        Precision = -1        Size = 100      end          item        Name = 'faal'        DataType = ftBoolean      Precision = -1      end          item        Name = 'olusturulma_tarihi'        DataType = ftDateTime        Precision = -1      end>    Database = PQConnection1    Transaction = SQLTransaction1    SQL.Strings = (      'SELECT okytno, kullanici_ismi, faal, olusturulma_tarihi'      'FROM sch_test.kullanicilar'    )    Params = <>    left = 368    top = 37  end  object DataSource9: TDataSource    DataSet = SQLQuery1    left = 472    top = 37  end  object SQLTransaction1: TSQLTransaction    Active = True    Database = PQConnection1    left = 248    top = 112  endend ---------------------------------------------------------------------- tr_escape · 2019-07-24 11:08 What version do you using of postgresql? ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 11:41 PostgreSQL verison is 11. ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 11:44 In the meantime, I changed the sql table creation script. And I tried again. He keeps making the same mistake. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i CREATE TABLE SCH_ACSHB.KULLANICILAR3(   OKYTNO               SERIAL          NOT NULL,        CONSTRAINT PK__KULLANICILAR3__OKYTNO PRIMARY KEY(OKYTNO),      KULLANICI_ISMI       VARCHAR(100)    NOT NULL,      CONSTRAINT UK__KULLANICILAR3__KULLANICI_ISMI UNIQUE (KULLANICI_ISMI),   FAAL                 BOOLEAN         NOT NULL    DEFAULT FALSE,   OLUSTURULMA_TARIHI   TIMESTAMP       NOT NULL    DEFAULT NOW());Select sql script: Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT OKYTNO, "KULLANICI_ISMI", FAAL, "OLUSTURULMA_TARIHI"FROM SCH_ACSHB.KULLANICILAR3ORDER BY KULLANICI_ISMI I know that there is no upper-case/lower-case separation. But why is he doing this? Could it be about the language of the database? Selamlar. ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 11:54 I am using DBEAVER ce. Both select statements below give no errors. It works and the data comes in. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT OKYTNO, KULLANICI_ISMI, FAAL, OLUSTURULMA_TARIHIFROM SCH_ACSHB.KULLANICILAR3ORDER BY KULLANICI_ISMI; Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT okytno, kullanici_ismi, faal, olusturulma_tarihiFROM sch_acshb.kullanicilar3;I think DBEAVER is made in java and uses jdbc. Why doesn't he make that mistake, but there's an error with these free pascal components. ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 12:05 Hello; I'm connecting to the same database as PHP. And I can pull the data. This error only occurs when working with lazarus. Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i          PostgreSQL Veritabanına PHP den bağlanabiliyorum.    

Kullanıcılar Listesi

    ";  while ($row = pg_fetch_assoc($result)) {        echo "";        echo "" . $row['okytno'] . "";      echo "" . $row['kullanici_ismi'] . "";        echo "" . $row['faal'] . "";        echo "" . $row['olusturulma_tarihi'] . "";        echo "";    }    echo ""; ?>      ---------------------------------------------------------------------- Ali KOCA · 2019-07-24 12:16 OS: Linux MX Last Version (MX-18.3_x64, with a 64 bit kernel) Lazarus: 2.0.2 FPC: 3.0.4 PostgreS: 11.4 (Debian 11.4-1.pgdg90+1) Error: qKullanicilar : Field not found : "kullanici_ismi" ---------------------------------------------------------------------- tr_escape · 2019-07-25 07:36 Quote from: Ali KOCA on July 24, 2019, 02:16:09 pm OS: Linux MX Last Version (MX-18.3_x64, with a 64 bit kernel) Lazarus: 2.0.2 FPC: 3.0.4 PostgreS: 11.4 (Debian 11.4-1.pgdg90+1) Error: qKullanicilar : Field not found : "kullanici_ismi" Actually I am using win64 but I will try on linux too. So I tried by psqlODBC dlls and zeos dbo I got only catalog names in windows. I couldn't get table names too maybe the zeos team should work on it. Note: My postgresql version is 11.4 64 bits but my client dll is 32 bits. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object Form1: TForm1  Left = 377  Height = 360  Top = 176  Width = 845  Caption = 'Form1'  DesignTimePPI = 144  LCLVersion = '2.1.0.0'  object DataSource1: TDataSource    Left = 100    Top = 106  end  object ZConnection1: TZConnection    ControlsCodePage = cCP_UTF8    AutoEncodeStrings = False    ClientCodepage = 'UTF8'    Catalog = 'db_test'    Properties.Strings = (      'AutoEncodeStrings='      'codepage=UTF8'    )    Connected = True    DesignConnection = True  HostName = '127.0.0.1'    Port = 5432    User = 'postgres'    Password = 'post1234'    Protocol = 'postgresql'    LibraryLocation = 'C:\Program Files (x86)\PostgreSQL\psqlODBC\bin\libpq.dll'    Left = 272    Top = 24  end  object ZTable1: TZTable    Connection = ZConnection1    Left = 272    Top = 106  endend ---------------------------------------------------------------------- Ali KOCA · 2019-07-26 08:42 I've tried the other components. The result has not changed. It's like a problem with lazarus. ---------------------------------------------------------------------- tr_escape · 2019-07-26 09:20 Quote from: Ali KOCA on July 26, 2019, 10:42:30 amI've tried the other components. The result has not changed. It's like a problem with lazarus. Maybe, but to be sure you have try by last know stable version of the PostgreSQL (9.6 I think) and Lazarus's DB components (also ZeosDBO). If you wish you can create a bug report about your work-around. ---------------------------------------------------------------------- Ali KOCA · 2019-07-26 12:37 Hello; Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT okytno, kullanici_ismi as kullanici, faal, olusturulma_tarihi as tarihFROM kullanicilar; If I write it this way, it doesn't give an error. Do you think of anything? ---------------------------------------------------------------------- Ali KOCA · 2019-08-01 09:00 Hi. SELECT OKYTNO, "kullanici_ismi" FROM kullanicilar; This is the way it works via dbeaver. However, Lazarus says he could not find the column again. SELECT OKYTNO, "KULLANICI_ISMI" FROM kullanicilar; In this way, neither dbeaver nor over lazarus does not work. The double quotes character (") provides upper case separation. select  kullanici_ismi as isimisimisimis, kullanici_ismi as is_im FROM kullanicilar; That's how it not works. select  kullanici_ismi as is_im FROM kullanicilar; That's how it works. ---------------------------------------------------------------------- Ali KOCA · 2019-08-01 09:01 Hi. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT OKYTNO, "kullanici_ismi"FROM kullanicilar;This is the way it works via dbeaver. However, Lazarus says he could not find the column again. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT OKYTNO, "KULLANICI_ISMI"FROM kullanicilar;In this way, neither dbeaver nor over lazarus does not work. The double quotes character (") provides upper case separation. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i select  kullanici_ismi as isimisimisimis, kullanici_ismi as is_imFROM kullanicilar;That's how it not works. Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i select  kullanici_ismi as is_imFROM kullanicilar; That's how it works. ---------------------------------------------------------------------- Ali KOCA · 2019-08-01 09:05 Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i select  kullanici_ismi as is_imFROM kullanicilar;  And there is both "i" and "_". I don't think it's about the Turkish locale. And I've never had such a problem except postgres. ---------------------------------------------------------------------- altanbozoglu · 2019-12-01 17:33 Hi; It's been a long time ago, but maybe this solution might work. The problem is that lazarus and fpc treat unicode strings differently. If you test with a simple console application, you will see that the queries are running. The problem is somewhat related to the cwstring unit. In my opinion, the best thing to do is to run the database part as a dynamic link library. I made a very simple example below. Library Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  library mydatalink; {$mode objfpc}{$H+} uses   Classes, SysUtils, parentunit, ZDataset, ZConnection, db; function ServerCnn():Boolean cdecl;Begin  lasterror := False; try  SQLServerCnn := TZConnection.Create(nil);  SQLServerCnn.Protocol  := 'postgresql';  SQLServerCnn.Database  := 'yourdatabasename';  SQLServerCnn.User      := 'usernamame';  SQLServerCnn.Password  := 'password';  SQLServerCnn.HostName  := 'serverip';  SQLServerCnn.Connected := True;  Result := SQLServerCnn.Connected;  Except on E : Exception do  Begin    lasterror    := True;    ErrorClass   := E.ClassName;    ErrorMessage := E.Message;  end; end;end; function SQLrun( SQLText: String):TDataSet; cdecl;var sql:TZQuery;Begin  lasterror := False;  try    sql := TZQuery.Create(SQLServerCnn);    sql.Connection := SQLServerCnn;    sql.SQL.Text := SQLText;    sql.Open;    Result := sql;    Except on E : Exception do    Begin      lasterror    := True;      ErrorClass   := E.ClassName;      ErrorMessage := E.Message;      Result := nil;    end;  end;end; function ErrorExsist():Boolean; cdecl;Begin  Result := lasterror;end; function GetErrorClass():String; cdecl;Begin  Result := ErrorClass;end; function GetErrorMessage():String; cdecl;Begin  Result := ErrorMessage;end;  exportsServerCnn, SQLrun, ErrorExsist, GetErrorClass, GetErrorMessage;end. //-------------------------------- ------------------------------ unit parentunit; {$mode objfpc}{$H+} interface uses  Classes, ZConnection;  type    { TParentObject }    TParentObject = class(TComponent)   private   public     connected:Boolean;     constructor Create(AOwner: TComponent); override;   end;  var   ParentObj:TParentObject;   lasterror:Boolean;   ErrorClass:String;   ErrorMessage:String;   SQLServerCnn:TZConnection; implementation   { TParentObject } constructor TParentObject.Create(AOwner: TComponent);begin   inherited;end;  end.  Note: After compiling the dynamic link library, remember to copy it to /usr/lib Sample Application Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    //...  function ServerCnn():Boolean cdecl; external 'libmydatalink.so';  function SQLrun( SQLText: String):TDataSet; cdecl; external 'libmydatalink.so';  function ErrorExsist():Boolean; cdecl; external 'libmydatalink.so';  function GetErrorClass():String; cdecl; external 'libmydatalink.so';  function GetErrorMessage():String; cdecl; external 'libmydatalink.so'; var  Form1: TForm1; implementation  {$R *.lfm} { TForm1 }    procedure TForm1.Button1Click(Sender: TObject);begin if ServerCnn() then   ShowMessage('Connected');end; procedure TForm1.Button2Click(Sender: TObject);begin  DataSource1.DataSet := SQLrun('select * from testtable');  if ErrorExsist() then  Memo1.Lines.Text := GetErrorMessage();end;         Cheers..