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.
TMyConnection.GetFieldNames
-
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:
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;Thanks, I managed to write the same using a query to the information_schema database (before your reply):
It solved my problem, so I will probably go on ordering a license soon...
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;
-
AndreyZ
-
AndreyZ
You can also download the SDAC documentation in the CHM format here: http://www.devart.com/sdac/sdacchm.zip