metadata for a table

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
yc1965
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.05.2009, 09:40
Location: Istanbul

metadata for a table

Post by yc1965 »

Hi,

I wonder if there is a way of getting the metadata (such as field descriptions) for a table?

Thanks in advance
Regards
Yusuf
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

Take a look at the Zeos component called ZSQLMetadata, where you can find metadata info about tables, views
yc1965
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.05.2009, 09:40
Location: Istanbul

Post by yc1965 »

I was aware of that component.
Just looking for something like similiar to
Connection.GetTableFields('TBL_NAME')

Thanks again
Yusuf
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

In that case you could add these functions to the zeoslib component yourself or (even better) make a TMyZConnection=class(TZConnection) component adding these functions.

We can't just start to add this kind of functions for all properties just when someone asks it. But I can promise you one exception : if you write a generic procedure like GetMetadataList(Metadatatype, Column, [condition_field_array],[condition_value_array], List) and use this to re-implement the already existing metadata functions of TZConnection, I'll include this change into the official zeoslib library. (Implement in ZDbcMetadata.pas, add to interface and write a wrapper in zconnection.pas)

Just have a look at this sample:

Code: Select all

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;
and

Code: Select all

function TZSQLMetadata.CreateResultSet(const SQL: string; MaxRows: Integer):
  IZResultSet;
var
  Metadata: IZDatabaseMetadata;
begin
  Connection.ShowSQLHourGlass;
  try
    Metadata := Connection.DbcConnection.GetMetadata;

    case FMetadataType of
      mdProcedures:
        Result := Metadata.GetProcedures(FCatalog, FSchema, FProcedureName);
      mdProcedureColumns:
        Result := Metadata.GetProcedureColumns(FCatalog, FSchema,
          FProcedureName, FColumnName);
      mdTables:
        Result := Metadata.GetTables(FCatalog, FSchema, FTableName, nil);
      mdSchemas:
        Result := Metadata.GetSchemas;
      mdCatalogs:
        Result := Metadata.GetCatalogs;
      mdTableTypes:
        Result := Metadata.GetTableTypes;
      mdColumns:
        Result := Metadata.GetColumns(FCatalog, FSchema, FTableName,
          FColumnName);
      mdColumnPrivileges:
        Result := Metadata.GetColumnPrivileges(FCatalog, FSchema, FTableName,
          FColumnName);
      mdTablePrivileges:
        Result := Metadata.GetTablePrivileges(FCatalog, FSchema, FTableName);
      mdBestRowIdentifier:
        Result := Metadata.GetBestRowIdentifier(FCatalog, FSchema, FTableName,
          FScope, FNullable);
      mdVersionColumns:
        Result := Metadata.GetVersionColumns(FCatalog, FSchema, FTableName);
      mdPrimaryKeys:
        Result := Metadata.GetPrimaryKeys(FCatalog, FSchema, FTableName);
      mdImportedKeys:
        Result := Metadata.GetImportedKeys(FCatalog, FSchema, FTableName);
      mdExportedKeys:
        Result := Metadata.GetExportedKeys(FCatalog, FSchema, FTableName);
      mdCrossReference:
        Result := Metadata.GetCrossReference(FCatalog, FSchema, FTableName,
          FForeignCatalog, FForeignSchema, FForeignTableName);
      mdTypeInfo:
        Result := Metadata.GetTypeInfo;
      mdIndexInfo:
        Result := Metadata.GetIndexInfo(FCatalog, FSchema, FTableName, FUnique,
          FApproximate);
      mdSequences:
        Result := Metadata.GetSequences(FCatalog, FSchema, FSequenceName);
      mdUserDefinedTypes:
        Result := Metadata.GetUDTs(FCatalog, FSchema, FTypeName, nil);
     end;
  finally
    Connection.HideSQLHourGlass;
  end;
end;
I really hope you take the time to do this... It would be a nice feature for all the community.

Mark
Image
yc1965
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 05.05.2009, 09:40
Location: Istanbul

Post by yc1965 »

Thanks mdaems,
Yeah I will be happy to give you guys a hand.
I see what I can do.:D

Regards
Yusuf
Post Reply