Zeos 8.0 + firebird 3 problem with generated fields

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
Hatti
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 16.10.2024, 07:53

Zeos 8.0 + firebird 3 problem with generated fields

Post by Hatti »

Hi,

On Monday, I upgraded to ZEOS 8.0, changed Protocol to "Firebird" in TZConnection, removed "AutoEncodeStrings" from .lfm (as asked by compiler) and compiled my program. (Lazarus version 3.6; FPC 3.2.2, Zeoslib 8.0, Firebird 3.??)

Now I got the Error:
Projekt Etiquette hat Exception-Klasse >>EZDatabasError<< augelöst mit der Meldung:
Field ID is required, but not supplied.
Field "ID" is an autoincrement bigint field, Generator and Trigger exist, the program performed fine with ZEOS 7.2.

Code: Select all

  
  tsql.Open;
  For vi := 1 To eeti.Value Do
    Begin
      tsql.Append;
      tsql.FieldByName('de').AsInteger := vi;
      tsql.FieldByName('a').AsInteger := eEti.Value;  
      .......
      tsql.ApplyUpdates;   <<=== error occurs here
    End;
Doing some I-Net research didn't help.
What did I miss?


Thank-you,
Hatti

P.S. I tried compiling another app, with same runtime-error, except the autoincrement field has the name CliID
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Zeos 8.0 + firebird 3 problem with generated fields

Post by marsupilami »

Hello Hatti,

Zeos 8 now (correctly) detects that your ID field is required. Zeos will also consider to use it for updates if it is a promary key. Zeos doesn't detect that the field value gets filled in by a trigger. Also a big problem for Zeos would be that it doesn't know the primary key value for your newly added record. Depending on your use case there are two possibilies to fix this:

1) You want to work with the dataset (tsql) after you have inserted the data. In that case, it is recommended to use a TZSequence object to supply the values:
  • Add a TZSequence object to your project
  • set the SequenceName property of your TZSequenceObject to your generator name
  • in your Query (tsql) set the Sequence property to the new TZSequence object
  • Set tsql.SequenceField to your id field (ID in your example)
This way Zeos will fetch the sequence value from the database and insert it into your query before you call post. This has the added value for you that Zeos will know the value of your ID field when you do other operations on tsql.
One more note: ApplyUpdates is part of the cached updates machanism. This shouldn't be needed in modern applications anymore. In your loop please simply use the tsql.Post.

2) You only want to insert values into the table and don't want to work with the values in tsql afterwards. In this case you should change your operation to use an insert statement:

Code: Select all

  tsql.Close;
  tsql.SQL.Text := 'insert into sometable (de, a, ...) values (:de, :a, ....)';
  For vi := 1 To eeti.Value Do
    Begin
      tsql.ParamByName('de').AsInteger := vi;
      tsql.ParamByName('a').AsInteger := eEti.Value;  
      .......
      tsql.ExecSQL;   <<=== no error should occur here ;o)
    End;
[code]
In this example Zeos will not cache values in memory. The insert statement is just sent to the database.
Hatti
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 16.10.2024, 07:53

Re: Zeos 8.0 + firebird 3 problem with generated fields

Post by Hatti »

Hi,

I hate this self-made newbie programmers! (myself :( )

Added a TZSequence, changed a TMemoField to TZBlobField and :shock: everything works fine.

marsupilami, thanks a lot for quick help.

regards,
Hatti

P.S.: I really like to know how many of these self-healing / self-improving / self-solving errors are still slumbering around in my programmes.
Post Reply