Is a TField in primary key?
-
chkaufmann
- Posts: 82
- Joined: Sat 01 Jul 2006 11:42
Is a TField in primary key?
Hi,
after loading a TDataSet I would like to know, if a field is used in the primary key index. I tried the following code, which seems to work (at least with Firebird)
m.MetaDataKind := 'IndexColumns';
m.Restrictions.Values['TABLE_SCHEMA'] := FUniConnection.SpecificOptions.Values['Schema'];
m.Restrictions.Values['TABLE_NAME'] := ATableName;
m.Restrictions.Values['UNIQUE'] := '1';
m.Open;
while not m.Eof do begin
Result.Include(m.FieldByName('COLUMN_NAME').AsString);
m.Next;
end;
But is there a way to read the information from the TField directly? E.g. like from ProviderFlags or FieldKind?
cu Christian
after loading a TDataSet I would like to know, if a field is used in the primary key index. I tried the following code, which seems to work (at least with Firebird)
m.MetaDataKind := 'IndexColumns';
m.Restrictions.Values['TABLE_SCHEMA'] := FUniConnection.SpecificOptions.Values['Schema'];
m.Restrictions.Values['TABLE_NAME'] := ATableName;
m.Restrictions.Values['UNIQUE'] := '1';
m.Open;
while not m.Eof do begin
Result.Include(m.FieldByName('COLUMN_NAME').AsString);
m.Next;
end;
But is there a way to read the information from the TField directly? E.g. like from ProviderFlags or FieldKind?
cu Christian
-
AndreyZ
Hello,
To determine primary key fields for MySQL and SQL Server, you can use the following code:For all other database servers UniDAC supports, you should use the TUniMetaData component. We will investigate ways of implementing unified functionality for retrieving primary key fields.
To determine primary key fields for MySQL and SQL Server, you can use the following code:
Code: Select all
if UniQuery.GetFieldDesc(UniQuery.Fields[0].FieldNo).IsKey then
ShowMessage('Primary key field');-
chkaufmann
- Posts: 82
- Joined: Sat 01 Jul 2006 11:42
-
chkaufmann
- Posts: 82
- Joined: Sat 01 Jul 2006 11:42
-
AndreyZ
Re: Is a TField in primary key?
Is this implemented yet?AndreyZ wrote:We will try to implement this functionality in one of the nearest UniDAC builds.
(just started evaluating UniDac and cant find anything in BOL)
thanks
h
BTW: from chkaufsman´s solution
the following line:
Restrictions.Values['UNIQUE'] := '1';
doesnt seem to have any effect - ALL index-fields are listed, not only PK-fields
(UniDAC 5.2.6)
Re: Is a TField in primary key?
Hello,
Yes, it is already done.
In order for only primary keys to be displayed, you can use the following code:
Yes, it is already done.
In order for only primary keys to be displayed, you can use the following code:
Code: Select all
UniMetaData1.MetaDataKind := 'Constraints';
UniMetaData1.Restrictions.Values['CONSTRAINT_TYPE'] := 'PRIMARY KEY';
UniMetaData1.Open;