How to identify primary key field(s)

The 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
Post Reply
ertank
Senior Boarder
Senior Boarder
Posts: 53
Joined: 02.06.2017, 12:00

How to identify primary key field(s)

Post by ertank »

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
Senior Boarder
Senior Boarder
Posts: 53
Joined: 02.06.2017, 12:00

Re: How to identify primary key field(s)

Post by ertank »

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/Retrie ... ey_columns
Fr0sT
Zeos Dev Team
Zeos Dev Team
Posts: 280
Joined: 08.05.2014, 12:08

Re: How to identify primary key field(s)

Post by Fr0sT »

TZPostgreSQLDatabaseMetadata.UncachedGetPrimaryKeys ?
ertank
Senior Boarder
Senior Boarder
Posts: 53
Joined: 02.06.2017, 12:00

Re: How to identify primary key field(s)

Post by ertank »

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
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: How to identify primary key field(s)

Post by marsupilami »

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
Post Reply