Hier mal die ganze Funktion "FindPrimaryKey"
Delphi-Quellcode:
function FindPrimaryKey: PFieldDesc;
var
I: Integer;
IndexDesc: PIndexDesc;
begin
Result := nil;
if SqlParser.Tables.Count = 0 then Exit;
{ Find primary key }
IndexDesc := nil;
for I := 0 to SqlBuffer.SqlIndices.Count-1 do
if StrCaseCmp(SqlBuffer.SqlIndices[I].Table, SqlParser.Tables[0])
and (SqlBuffer.SqlIndices[I].KeyType = ktPrimary) then
begin
IndexDesc := SqlBuffer.SqlIndices[I];
Break;
end;
{ Check primary key }
if (IndexDesc = nil) or (IndexDesc.FieldCount <> 1) then Exit;
Result := SqlBuffer.SqlFields.FindByName(SqlParser.Tables[0],
IndexDesc.Fields[0]);
if Result = nil then Exit;
//if Result.FieldType <> ftInteger then
if not (Result.FieldType in [ftSmallint, ftInteger, ftFloat, ftBCD
{$IFNDEF VER100}, ftLargeInt{$ENDIF}]) then
Result := nil;
end;
begin
inherited;
FieldDescKey := FindPrimaryKey;
end;