ClientDataSet and serial fields

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
badmood
Posts: 37
Joined: Thu 29 Jan 2009 23:28
Location: Italy

ClientDataSet and serial fields

Post by badmood » Mon 16 Feb 2009 22:49

Hi,

I'm using a PgQuery -> DataSetProvider -> ClientDataSet -> PgDataSource "chain" to manage the data.

It's all ok, but...

If I have a table with a field (the primary key) defined as serial data type (and in the query properties the key and the sequence name are correctly defined), the first record you insert is ok (and it takes, for example, the id value of 1), but when you post a second one you receive an error message of "duplicate key" or similar instead of the id 2.
On every post I call a StartTransaction, ApplyUpdates(0), Commit.

If I use only PgQuery -> PgDataSource is all ok.

Is there something I'm doing wrong?

Thanks in advance.

Sergio

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 20 Feb 2009 09:06

TClientDataSet cannot refresh value of ID field. When it is filled in the TPgQuery component with a value from the sequence, in TClientDataSet the field keeps NULL value.

Because you have set the KeyFields property, you cannot insert two records with the same value (NULL) of ID field into the TClientDataSet component.

You should call the Refresh method of TClientDataSet each time after ApplyUpdates for the component read new values of ID field.

badmood
Posts: 37
Joined: Thu 29 Jan 2009 23:28
Location: Italy

Post by badmood » Fri 20 Feb 2009 10:25

Thank you!

I'll follow your indications as soon as possibile.


Sergio

Post Reply