Getting Primary Key fields of an ADO dataset...
Hi,
how do I get the fields that make up the primary key of an ADO dataset?
My provider is SQL Server 2000.
Point 1:
--------
For some reason, iterating through each of
TADODataSet.Fields[x].IsIndexField property always returns false.
Point 2:
--------
After some delving into ADODB and ADOInt, and reading "Programming ADO"
by David Sceppa, I came upon the Attributes property of fields in
native ADO,
From reading ADODB, I surmised that the Attributes property is filled in
this section of code...line 5892
procedure TADODataSet.CreateDataSet;
procedure CreateFields;
var
Options, I: Integer;
begin
for I := 0 to FieldDefs.Count - 1 do
with FieldDefs[I] do
begin
if Required then
Options := 0 else
Options := adFldIsNullable + adFldMayBeNull;
if (DataType in [ftMemo, ftBlob]) and (Size = 0) then
Size := High(Integer);
Recordset.Fields.Append(Name, FieldTypeToADOType(DataType), Size,
Options);
end;
end;
begin
CheckInactive;
InitFieldDefsFromFields;
FRecordsetObject := CreateADOObject(CLASS_Recordset) as _Recordset;
Sceppa's text notes that the Attribute property, adFldKeyColumn, will
indicate if a field is part of the primary key. However, according to
the code above, the CreateFields function doesn't even attempt to make
this property part of the Options property passed into the creation of
the Fields property. I'm assuming from this code that Delphi does not
make use of this property either (adFldKeyColumn). All Delphi seems to
care about the native ADO field properties is whether they are required
or not...
How can I then get the fields that make up the primary key? Is there a
generic SQL statement to do that?
Thanks a bunch...
JB