Page 1 of 1

How do you use TOraMetaData to get a list of tables?

Posted: Mon 22 Aug 2011 02:50
by 1222tmiller
I want to get a list of all tables for a specific schema. It is clear in the documentation how to set the component and activate it, but doesn't explain how to actually get to the information.

Once I have a list of tables, I will need to retrieve the columns for a specific table. Again I get on how to add a restriction, but once active, how I get to the column information?

I am developing an adhoc query tool. Thanks.

Posted: Mon 22 Aug 2011 09:41
by jfudickar
What about

Code: Select all

SELECT * FROM ALL_TABLES WHERE OWNER = :OWNER'
and

Code: Select all

SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_OWNER = :OWNER AND TABLE_NAME = :TABLE_NAME
Regards
Jens

Posted: Mon 22 Aug 2011 12:34
by 1222tmiller
jfudickar wrote:What about

Code: Select all

SELECT * FROM ALL_TABLES WHERE OWNER = :OWNER'
and

Code: Select all

SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_OWNER = :OWNER AND TABLE_NAME = :TABLE_NAME
Regards
Jens
Sure I can do it that way, but then what is the MetaData component for?

Posted: Wed 24 Aug 2011 09:13
by AndreyZ
To obtain the list of tables and the list of columns using the TOraMetaData component, you can use the following code:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  strTables, strColumns: TStringList;
begin
  strTables := nil;
  strColumns := nil;
  try
    // obtaining the list of tables
    OraMetaData1.MetaDataKind := 'Tables';
    OraMetaData1.Restrictions.Values['TABLE_SCHEMA'] := '"schemaname"';
    OraMetaData1.Open;
    strTables := TStringList.Create;
    while not OraMetaData1.Eof do begin
      strTables.Add(OraMetaData1.FieldByName('TABLE_NAME').AsString);
      OraMetaData1.Next;
    end;
    OraMetaData1.Close;
    // obtaining the list of columns
    OraMetaData1.MetaDataKind := 'Columns';
    OraMetaData1.Restrictions.Values['TABLE_SCHEMA'] := '"schemaname"';
    OraMetaData1.Restrictions.Values['TABLE_NAME'] := '"tablename"';
    OraMetaData1.Open;
    strColumns := TStringList.Create;
    while not OraMetaData1.Eof do begin
      strColumns.Add(OraMetaData1.FieldByName('COLUMN_NAME').AsString);
      OraMetaData1.Next;
    end;
  finally
    if Assigned(strColumns) then
      FreeAndNil(strColumns);
    if Assigned(strTables) then
      FreeAndNil(strTables);
  end;
end;