Retrieving Index Fields

Retrieving Index Fields

Postby lsc82 » Thu 17 Mar 2005 09:10

Hi,

I'm using D5, MyDac 3.5.0.17, InnoDB.

In my application I need to retrieve the fields of the primary key.

I've try using IndexDefs[0].Fields, but it is slow (about 0.10~0.30 s).

Is there a way of obtaining these fields in a faster way?

Thanks

Luca
lsc82
 
Posts: 16
Joined: Tue 28 Dec 2004 14:49
Location: Padova, Italy

Retrieve Primary Key Field

Postby kenny » Thu 17 Mar 2005 09:40

Hi,

I had wrote the function :

function GetKeyField(strTable:string;QGetKeyField:TMyQuery):string;
var
strIndex : string;
Begin
strIndex := '';
With QGetKeyField Do BEgin
Close;
SQL.Clear;
SQL.Add('SHOW INDEX FROM ' + strTable);
Open;
End;

If QGetKeyField.RecordCount = 0 Then
Result := ''
Else
Begin
While Not QGetKeyField.Eof Do Begin
If QGetKeyField.FieldByName('Key_Name').AsString='PRIMARY' Then
Begin
If strIndex='' Then
strIndex := TRIM(QGetKeyField.FieldByName('Column_Name').AsString) + ','
Else
strIndex := strIndex + TRIM(QGetKeyField.FieldByName('Column_Name').AsString) + ',';
End;
QGetKeyField.Next;
End;
Delete(strIndex,Length(strIndex),1);
Result := strIndex;
End;
End;


Hope it can help
kenny
 
Posts: 43
Joined: Mon 15 Nov 2004 08:48
Location: Malaysia

Postby Ikar » Thu 17 Mar 2005 14:33

Probably, it will be enough to have information from TCustomMyDataSet.PSGetKeyFields - it returns a list of key fields minimal requested for creating, for example, UPDATE statement.

Another methods require additional call to the server.
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56


Return to MySQL Data Access Components