AnyDAC offers TADMetaInfoQuery components and some TADConnection methods to retrieve metadata from a database.
TADConnection offers few GetXxxxNames simple to use methods returning the database object names list:
These method are useful when:
For example, GetTableNames method retrieves the table, view and synonym names from the current database and schema. To call it use the code:
ADConnection1.GetTableNames('Northwind', 'dbo', '', Memo1.Lines);
Use the ACatalogName and / or ASchemaName arguments to restrict the returned list to the specified catalog and / or schema. If they are not specified, then all "visible" objects will be returned or the objects in the current database / schema. That depends on the DBMS. Note, some DBMS (MS Access) may return error if the schema / catalog is specified and it is not supported by the DBMS.
Additionally, the application may restrict object list using AScopes argument, basing on the object scope. And the APattern argument, which is the LIKE search mask, which will be applied to object names.
The similar method you can found at TADCustomManager class.
See the AnyDAC demo for more details: AnyDAC\Samples\Comp Layer\TADConnection\GetFieldNames.
The TADMetaInfoQuery is the dataset component allowing to query and browse the metadata lists. To do that set the Connection, MetaInfoKind and optionally the CatalogName, SchemaName, BaseObjectName, ObjectName properties, and open the dataset. To get the tables list use the code:
ADMetaInfoQuery1.Connection := ADConnection1; ADMetaInfoQuery1.MetaInfoKind := mkTables; ADMetaInfoQuery1.Open;
For the dataset structure description read the "Metadata Structure" chapter. If a DBMS does not support some particular metadata kind, for example SQL Server does not support mkGenerators, then empty dataset will be returned. The metadata dataset is read-only and cannot be edited.
Excluding fiMeta from FetchOptions.Cache does not invalidate the metadata cache. All cached metadata remains in cache until it next usage. To refresh the metadata cache for a specified object or in full use the TADConnection.RefreshMetadataCache.
To get current catalog and schema name, use TADConnection.ConnectionIntf.CurrentCatalog and CurrentSchema. To change current catalog or schema, assign new value to these properties.
MetaCurCatalog and MetaCurSchema allows to override the information returned by the database session. For some databases it may be required to use these parameters to specify correct values, because API returns incorrect ones.
What do you think about this topic? Send feedback!