Page 1 of 1
TMyConnection.GetFieldNames
Posted: Fri 08 Jul 2011 08:52
by jouniaro
Hi, I am evaluating your components, because we have odd problems with TADOConnection to mysql.
But our system requires a way to get the field names for any table, using
TMyConnection.GetFieldNames(TableName: string;
List: TStrings);
similar to TAdoConnection.
Any help available? We are in a hurry since our final tests are blocking now due to this strange issue with ADO/MySQL, which only appears in the final system and not in any of our test installations, so I am looking for any replacement ASAP.
Posted: Fri 08 Jul 2011 12:58
by AndreyZ
Hello,
For the time being, MyDAC doesn't have such functionality. We will investigate the possibility of adding this functionality in the future. You can use the TMyMetaData component to obtain the same result. Here is an example:
Code: Select all
procedure GetFieldNames(con: TMyConnection; TableName: string; List: TStrings);
var
md: TMyMetaData;
begin
md := TMyMetaData.Create(nil);
try
md.Connection := con;
md.MetaDataKind := 'Columns';
md.Restrictions.Values['TABLE_SCHEMA'] := md.Connection.Database;
md.Restrictions.Values['TABLE_NAME'] := TableName;
md.Open;
List.Clear;
while not md.Eof do begin
List.Add(md.FieldByName('COLUMN_NAME').AsString);
md.Next;
end;
finally
md.Free;
end;
end;
Posted: Sat 09 Jul 2011 20:07
by jouniaro
Thanks, I managed to write the same using a query to the information_schema database (before your reply):
Code: Select all
if Connection.Connected then
begin
C := TMyConnection.Create(nil);
Q := TMyQuery.Create(nil);
try
C.Server := Connection.Server;
C.Username := Connection.Username;
C.Password := Connection.Password;
C.Database := 'information_schema';
Q.Connection := C;
C.Connect;
Q.SQL.Text := Format(
'select column_name from columns where table_schema=''%s'' and table_name=''%s''',
[Connection.Database, TableName]);
Q.Open;
List.Clear;
while not Q.Eof do
begin
List.Add(VarToStr(Q.FieldValues['column_name']));
Q.Next;
end;
finally
Q.Free;
C.Free;
end;
end;
It solved my problem, so I will probably go on ordering a license soon...
Posted: Mon 11 Jul 2011 11:41
by AndreyZ
To obtain field names, the TMyMetaData component executes a query to the information_schema database too. Therefore you can use any of these variants.
Posted: Mon 11 Jul 2011 11:58
by jouniaro
That's what I thought too. Unfortunately my Delphi XE help is broken and I could not restore it - but I downloaded the Delphi 7 version as well to get your help...
It seems TMyMetadata is in the pro package, so I won't need that

Posted: Mon 11 Jul 2011 13:42
by AndreyZ
You can also download the SDAC documentation in the CHM format here:
http://www.devart.com/sdac/sdacchm.zip