Page 1 of 1

DBGrid Append/Post on PostgreSQL table with identity column

Posted: Wed 01 Jan 2020 16:23
by ertank
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

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

Posted: Thu 09 Jan 2020 12:15
by MaximG
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;

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

Posted: Thu 09 Jan 2020 14:32
by ertank
That did solve my problem.

Thank you.

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

Posted: Fri 10 Jan 2020 09:28
by MaximG
We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning our product usage.