How to identify primary key field(s)

The BETA tester's forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
ertank
Junior Boarder
Junior Boarder
Posts: 30
Joined: 02.06.2017, 12:00

How to identify primary key field(s)

Postby ertank » 14.11.2017, 23:15

Hello,

I am using ZeosLib with Lazarus 1.8.0RC5, Raspberry Pi 3 running Stretch OS, PostgreSQ 9.6.5 database.

Given that I have table name, can I find primary key field (or fields) of that table using zeoslib?

If yes, I appreciate a small sample code, please.

Thanks
Ertan

ertank
Junior Boarder
Junior Boarder
Posts: 30
Joined: 02.06.2017, 12:00

Re: How to identify primary key field(s)

Postby ertank » 14.11.2017, 23:31

Seems like it is not quite possible to find it in an executed TZQuery, but it is possible to use a query for that matter. Below link seems to provide what is necessary
https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns

Fr0sT
Junior Boarder
Junior Boarder
Posts: 43
Joined: 08.05.2014, 12:08

Re: How to identify primary key field(s)

Postby Fr0sT » 15.11.2017, 07:52

TZPostgreSQLDatabaseMetadata.UncachedGetPrimaryKeys ?

ertank
Junior Boarder
Junior Boarder
Posts: 30
Joined: 02.06.2017, 12:00

Re: How to identify primary key field(s)

Postby ertank » 17.11.2017, 22:46

Fr0sT wrote:TZPostgreSQLDatabaseMetadata.UncachedGetPrimaryKeys ?

Hello Fr0sT,

Thanks for your help.

Unfortunately, I am not sure how I can use that function as it seems to be a protected function and used ZeosLib internals as far as I could understand.

If it is to strip SQL out of that function, I just lost myself in it doing that. However, I confirm my above SQL is working OK for PostgreSQL 9.6.4

Regards,
Ertan

marsupilami
Gold Boarder
Gold Boarder
Posts: 588
Joined: 17.01.2011, 14:17

Re: How to identify primary key field(s)

Postby marsupilami » 18.11.2017, 11:26

Hello Ertan,

(Uncached)GetPrimaryKeys is part of the DBC layer. It might be more easy to use the TZMetadata component. It works like a query. Set the metadata you want to retrive to primary key. Set the table name to your desired table name. Call the open method.

With best regards,

Jan


Return to “ZeosLib 7.2 Betatest Forum”

Who is online

Users browsing this forum: No registered users and 1 guest