GetTableNames and Firebird

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
signals
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 06.02.2010, 13:30

GetTableNames and Firebird

Post 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
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post 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;
signals
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 06.02.2010, 13:30

Post 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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
Post Reply