looking for primary key field

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Willo
Posts: 34
Joined: Thu 24 Aug 2006 18:29

looking for primary key field

Post by Willo » Fri 14 Dec 2007 16:27

Hi;

does any one knows if tere is a way to know which field is the primary key in a table?

i have a rutine that logs changes on a table at field level, but i need to log the record's primary key as well.



TIA

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 17 Dec 2007 08:49

You can use the DESCRIBE table_name command to get such information about a table.

You can determine key fields in a dataset by MyDAC means in the following way:

Code: Select all

var
  i: integer;
begin
  MyQuery1.Open;
  for i := 0 to MyQuery1.FieldCount - 1 do
    if MyQuery1.GetFieldDesc(MyQuery1.Fields[i].FieldName).IsKey then
      ShowMessage(MyQuery1.Fields[i].FieldName + ' is in key');

Post Reply