Page 1 of 1

TDatabase.GetFieldNames equivalent

Posted: Thu 02 Sep 2010 10:25
by Princess Innah
Hi. Is there an equivalent to the TDatabase.GetFieldNames method?

Posted: Thu 02 Sep 2010 14:37
by Dimon
We don't have exact equivalent for this function, but you can use TIBCMetaData for obtaining the same result. Here is an example:

Code: Select all

procedure GetFieldNames(Connection: TIBCConnection; const TableName: string; List: TStrings);
var
  IBCMetaData: TIBCMetaData;
begin
  IBCMetaData := TIBCMetaData.Create(nil);
  try
    IBCMetaData.Connection := Connection;
    IBCMetaData.MetaDataKind := 'Columns';
    IBCMetaData.Restrictions.Add('table_name=' + TableName);
    IBCMetaData.Open;
    IBCMetaData.First;
    List.Clear;
    while not IBCMetaData.Eof do begin
      List.Add(IBCMetaData.FieldByName('column_name').AsString);
      IBCMetaData.Next;
    end;
  finally
    IBCMetaData.Free;
  end;
end;

Posted: Fri 03 Sep 2010 05:01
by Princess Innah
Wow. That was fast. Thank you so much.