DBGrid Append/Post on PostgreSQL table with identity column

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

DBGrid Append/Post on PostgreSQL table with identity column

Post by ertank » Wed 01 Jan 2020 16:23

Hello,

I am using Delphi 10.3.3, UniDAC 8.1.2, PostgreSQL 12.1 on Windows 10 64Bit, targeting win32 executable.

I have a table created using following SQL:

Code: Select all

create table if not exists test1(
autoinc bigint generated by default as identity not null primary key,
abc varchar(20)
);
I use this table on a regular TDBGrid using TUniQuery. TUniQuery has following SQL:

Code: Select all

select * from test1
I have following codes in my form to open TUniQuery:

Code: Select all

  UniQuery1.Close();
  UniQuery1.Open();
  UniQuery1.FieldByName('autoinc').Required := False;
  UniQuery1.FieldByName('autoinc').AutoGenerateValue := arAutoInc;
This way, I can enter new rows only by writing data in abc column. However, I cannot see autoinc column values after posting new rows.

Is it possible to see autoinc column value right after posting? Without having to use close/open or refresh?

Thanks & regards,
Ertan

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: DBGrid Append/Post on PostgreSQL table with identity column

Post by MaximG » Thu 09 Jan 2020 12:15

You can use the DMLRefresh property to implement the behavior you described : https://www.devart.com/unidac/docs/deva ... efresh.htm

Code: Select all

 UniQuery1.DMLRefresh := True;
  UniQuery1.Close();
  UniQuery1.Open();
  UniQuery1.FieldByName('autoinc').Required := False;
  UniQuery1.FieldByName('autoinc').AutoGenerateValue := arAutoInc;

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: DBGrid Append/Post on PostgreSQL table with identity column

Post by ertank » Thu 09 Jan 2020 14:32

That did solve my problem.

Thank you.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: DBGrid Append/Post on PostgreSQL table with identity column

Post by MaximG » Fri 10 Jan 2020 09:28

We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning our product usage.

Post Reply