Hi,
I wonder if there is a way of getting the metadata (such as field descriptions) for a table?
Thanks in advance
Regards
Yusuf
metadata for a table
Moderators: gto, cipto_kh, EgonHugeist
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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:
and
I really hope you take the time to do this... It would be a nice feature for all the community.
Mark
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;
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;
Mark