TZTable tries to set Identity column on insert

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
danielsap
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 12.04.2017, 06:12

TZTable tries to set Identity column on insert

Post by danielsap »

Hi,
I created simple application in Delphi - TZConnection, TZTable, TDataSource, TDBGrid.
Also created a table in FireBird with identity column
create table Perspective (
Id integer generated by default as identity primary key,
Name varchar(64)
);

When I run the application and type value for Name in the DBGrid,
and press down arrow button to insert the record, it throws an exception:
'Project ZeosTest raised exception class EZSQLException with message'SQL Error: validation error for column "PERSPECTIVE"."ID" value "***null***".
Error code - 625. Insert failed because a column definition includes validation constraints.
The SQL: INSERT INTO PERSPECTIVE (ID, NAME) VALUES (?, ?);'.

I tried to solve the problem by:
1. adding all fields in the TZTable
2. setting property 'AutoGenerateValue' to arAutoInc in the TZTable
3. setting property 'Required' to False in the TZTable

This application is very basic and a lot of people starts using components and database this way.
Also using simple table is used very often.
So, I expected this to work out of the box, just by connecting the components and to go smooth.

Can you give me some more information and may be some solution to this issue?

I'm using
Zeos 7.2.1-rc
Firebird-3.0.2.32703-0_Win32
Delphi XE3

Thanks
Daniel
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZTable tries to set Identity column on insert

Post by marsupilami »

Hello Daniel,

the answer is simple: Don't use autoinc because it is a mess with GUI-Applications. You better do it like this:
  • Create a Sequence (Generator in Firebird-Speak)
  • make your field to be just integer ot bigint
  • Add a TZSequence to your form, set the SequenceName property to the name of your newly created seqence
  • set the Sequence property of your TZTable object to the newly created TZSequence object
  • set the SequenceField property to your primary key field, where you want to insert the sequence value
Zeos will now automatically retrieve sequence values for you and store them in the field.

Internally Firebird is doing exatly this - it creates a before insert trigger and retrieves a new value from an automatically created sequence if the autoinc field is null. But only if you do it this way, Zeos can get all the information, it needs.

With best regards,

Jan
danielsap
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 12.04.2017, 06:12

Re: TZTable tries to set Identity column on insert

Post by danielsap »

Thank you, Jan
It works fine this way (y)
Post Reply