Page 1 of 1

GetTableNames and Firebird

Posted: 30.03.2010, 14:39
by signals
Is there a working example of how the GetTableNames function
works with Firebird that just displays the tables (but not any
system tables)?
The pattern patch parameters are very unclear to me as to how
they work. Thanks

Posted: 30.03.2010, 21:38
by seawolf
procedure TForm1.Button1Click(Sender: TObject);
var
MyList : TStringList;
i : integer;
begin
try
Lista := TStringList.Create;
ZConnection1.Connect;
ZConnection1.GetTableNames('',MyList);
for i := 0 to MyList.Count - 1 do
Memo1.Lines.Add(MyList);
ZConnection1.Disconnect;
finally
Lista.Free;
Lista := nil;
end;
end;

Hope this can helps .. anyway remember GetTableNames gives all the
tables, system tables too. If you don't don't want systemtable you could
do this:

procedure TForm1.Button1Click(Sender: TObject);
var
MyList : TStringList;
i : integer;
begin
try
Lista := TStringList.Create;
ZConnection1.Connect;
ZConnection1.GetTableNames('',MyList);
for i := 0 to MyList.Count - 1 do
if Pos('RDB$',UpperCase(MyList)) = 0 then Memo1.Lines.Add(MyList);
ZConnection1.Disconnect;
finally
Lista.Free;
Lista := nil;
end;
end;

Posted: 31.03.2010, 05:21
by signals
Thanks, that's pretty much what I figured out. My solution to what I needed ended
up being:

>======================================
oList.Clear ;
For nI := 0 to (FDatasets.Count - 1) do
Begin
// oCurrent := TZAbstractRODataset(FDatasets);
oCurrent := TzaTable(FDatasets[nI]) ;
cTable := Trim(UpperCase(oCurrent.TableName)) ;
If Length(cTable) > 0 then
oList.AddObject(cTable , TObject(oCurrent)) ;
End ;
oList.Sort ;
>======================================

This code is in a object that inherits from TZConnection and TzTable. I suspect
that the "blank" table name(s) I need to eliminate are the queries hooked to
the TzConnection.

Posted: 03.04.2010, 20:23
by mdaems
From ZConnection.pas :

Code: Select all


{**
  Fills string list with table names.
  @param tablePattern a pattern for table names.
  @param schemaPattern a pattern for schema names.
  @param types a TStringDynArray specifying the table types to look for.
    possible values can be found by reading
     TZConnection.DbcConnection.GetMetadata.GetTableTypes
     eg. for PostGreSQL this includes :'TABLE', 'VIEW', 'INDEX', 'SEQUENCE',
                                       'SYSTEM TABLE', 'SYSTEM TOAST TABLE',
                                       'SYSTEM TOAST INDEX', 'SYSTEM VIEW',
                                       'SYSTEM INDEX', 'TEMPORARY TABLE',
                                       'TEMPORARY INDEX'
  @param List a string list to fill out.
}
procedure TZConnection.GetTableNames(const tablePattern,schemaPattern: string; Types: TStringDynArray; List: TStrings);
var
  Metadata: IZDatabaseMetadata;
  ResultSet: IZResultSet;
begin
  CheckConnected;

  List.Clear;
  Metadata := DbcConnection.GetMetadata;
  ResultSet := Metadata.GetTables('', schemaPattern, tablePattern, types);
  while ResultSet.Next do
    List.Add(ResultSet.GetStringByName('TABLE_NAME'));
end;
From TZInterbase6DatabaseMetadata.UncachedGetTables you can see the table types supported for IB/FB are 'TABLE', 'VIEW' and 'SYSTEM TABLE'.

Mark