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
How to identify primary key field(s)
Re: How to identify primary key field(s)
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
https://wiki.postgresql.org/wiki/Retrie ... ey_columns
Re: How to identify primary key field(s)
TZPostgreSQLDatabaseMetadata.UncachedGetPrimaryKeys ?
Re: How to identify primary key field(s)
Hello Fr0sT,Fr0sT wrote:TZPostgreSQLDatabaseMetadata.UncachedGetPrimaryKeys ?
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
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: How to identify primary key field(s)
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
(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