How to handle serial(autoinc) fields with a grid?

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

How to handle serial(autoinc) fields with a grid?

Post by snorkel » Wed 26 Aug 2009 18:35

Hi,
I used to use the components from Microolap, and they seemed to handle serial(autoinc) fields automatically when used in a grid such as the one from DevExpress.

Currently if I have a table opened and I insert a row I have to refresh the whole dataset to get the autoinc number to populate.

Thanks,

Snorkel

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

Post by Plash » Thu 27 Aug 2009 07:28

You should set the DMLRefresh option of TPgQuery to True. In this case PgDAC generates INSERT statement with the RETURNING clause to get back inserted field values.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Thu 27 Aug 2009 14:16

Thanks for the info.
Does using returning work on all versions of PostgreSQL?
I thought that was a newer feature of 8.3 or 8.4.

Later,

Snorkel

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

Post by Plash » Fri 28 Aug 2009 08:48

RETURNING is supported starting with PostgreSQL 8.3. But there is no other way to get back a value generated in the database.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Fri 11 Sep 2009 18:52

Plash wrote:RETURNING is supported starting with PostgreSQL 8.3. But there is no other way to get back a value generated in the database.
I looked in the docs and it seems 8.2 also supports it:

http://www.postgresql.org/docs/8.2/inte ... nsert.html

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

Post by Plash » Mon 14 Sep 2009 07:40

You are right, RETURNING is supported starting with PostgreSQL 8.2.

Post Reply