Retrieving Index Fields

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
lsc82
Posts: 16
Joined: Tue 28 Dec 2004 14:49
Location: Padova, Italy

Retrieving Index Fields

Post by 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

kenny
Posts: 43
Joined: Mon 15 Nov 2004 08:48
Location: Malaysia
Contact:

Retrieve Primary Key Field

Post by 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

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by 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.

Post Reply