How to Handle AutoIncs (or SERIALS in Postgres)
Posted: 30.08.2008, 01:16
Halo,
I'm using TClientDataset, TDatasetProvider and TZQuery.
I have a postgreSQL database with a simple table with a field called id of type SERIAl and a field 'name' of type varchar(20).
I fould an article "How to use AutoInc fields with DataSnap" (http://dn.codegear.com/kr/article/20847) which describes how to handle the autoinc fields correctly. In brief, you should assign a negative value (eg. -1) to the "id" Field, call TClientDataset.ApplyChanges, and then TClientDataset.refresh to get the correct id value from the database.
I'm not sure if it is zeos or postgres as such, but the "id" fields are not excluded from the update statment, and they are stored in the table as negative values, so when I call TClientDataset.refresh, I get my id=-1 back from the database...
One thing which I noticed is, that the "id" field which is of type SERIAL seems not to be handled as an autoinc field. The property TClientDataset.FieldByName('id').Datetype indicates that it is an integer value not an autoinc.
Any Ideas how to manage this?
ps. its quite late now... so, if it is not clear what I mean, please excuse me, just tell me and I will try to describe it better
I'm using TClientDataset, TDatasetProvider and TZQuery.
I have a postgreSQL database with a simple table with a field called id of type SERIAl and a field 'name' of type varchar(20).
I fould an article "How to use AutoInc fields with DataSnap" (http://dn.codegear.com/kr/article/20847) which describes how to handle the autoinc fields correctly. In brief, you should assign a negative value (eg. -1) to the "id" Field, call TClientDataset.ApplyChanges, and then TClientDataset.refresh to get the correct id value from the database.
I'm not sure if it is zeos or postgres as such, but the "id" fields are not excluded from the update statment, and they are stored in the table as negative values, so when I call TClientDataset.refresh, I get my id=-1 back from the database...
One thing which I noticed is, that the "id" field which is of type SERIAL seems not to be handled as an autoinc field. The property TClientDataset.FieldByName('id').Datetype indicates that it is an integer value not an autoinc.
Any Ideas how to manage this?
ps. its quite late now... so, if it is not clear what I mean, please excuse me, just tell me and I will try to describe it better