Metadata Questions (FireDAC)
Go Up to FAQ (FireDAC)
This topic contains a list of questions and answers related to the metadata retrieval.
Q1: Is there a method to check if a table exists inside of a database?
A: There are two basic methods:
1)
try
FDQuery1.Open('select * from tab where 0 = 1');
Result := True;
except
on E: EFDDBEngineException do
if E.Kind = ekObjNotExists then
Result := False
else
raise;
end;
2)
var
oList: TStrings;
begin
oList := TStringList.Create;
try
FDConnection1.GetTableNames('', '', ATableName, oList, [osMy, osOther, osSystem],
[tkTable, tkTempTable, tkLocalTable]);
Result := oList.Count > 0;
finally
oList.Free;
end;
end;
The first one is more optimized.
Q2: For Oracle, is it possible to get the package procedures using TFDMetaInfoQuery?
A: The following code returns a list of procedures for the PACKAGE_NAME Oracle package.
FDMetaInfoQuery1.BaseObjectName := 'PACKAGE_NAME';
FDMetaInfoQuery1.MetaInfoKind := mkProcs;
FDMetaInfoQuery1.Open;
Q3: How can I get index names using TFDMetaInfoQuery?
A: The following code returns a list of indexes for the MY_TAB table.
FDMetaInfoQuery1.ObjectName := 'MY_TAB';
FDMetaInfoQuery1.MetaInfoKind := mkIndexes;
FDMetaInfoQuery1.Open;
Q4: Query Builder, design-time editors and metadata retrieval functions return object names belonging to my current schema, prefixed with schema/catalog name. How can I exclude it?
A: Two options:
- Set AFullName to False in the TFDConnection.GetXxxxName call;
- FireDAC has two general connection definition parameters - MetaDefCatalog and MetaDefSchema. Depending on the DBMS, either or both of them are supported (see FireDAC Database Connectivity for details). If the object belongs to a specified MetaDefCatalog catalog/MetaDefSchema schema, then this catalog/schema name will be excluded from an object name. So, set MetaDefCatalog/MetaDefSchema to your development catalog/schema name if you need to deploy your application to a different catalog/schema.
Q5: I am calling Oracle stored procedure using public synonym, but FireDAC always appends schema name to the stored procedure name. How can I avoid that?
A: FireDAC has two general connection definition parameters - MetaCurCatalog and MetaCurSchema. Depending on the DBMS, either or both of them are supported (see FireDAC Database Connectivity for details). Setting them to '*' will avoid usage of a corresponding name part in a full object name.