TAstaServerSocket.OnFetchMetaData
Applies
to
TAstaServerSocket
Declaration
type TAstaServerMetaDataEvent = procedure(Sender:
TObject;
ClientSocket: TCustomWinSocket; MetaRequest: TAstaMetaData;
DataBaseStr, Arg1, Arg2: string) of
object;
Description
ASTA clients require information about the server database, and coding the OnFetchMetaData event is
required for ASTA clients to be able to fetch tablenames, fieldnames, index information, foreign key information,
stored procedure names and columns and other assorted server database information. AstaClientDataSets
trigger this server side event using their MetaDataRequest
property.
The OnFetchMetaData event is currently NOT threaded and will return the AstaServerSocket.MetaDataSet to ASTA clients.
The following is an abridged version of the OnFetchMetaData event as coded on the AstaBDEServer. An important point is that whatever request that comes in from the client, the MetaData property is set on the TAstaServerSocket so that the correct information is streamed back to ASTA clients. The AstaBDEServer uses the ASTA component AstaBDEInfoTable to retrieve BDE information and the AstaODBCInfoDataSet to retrieve meta data information using components from www.odbcexpress.com. Source is available for these two ASTA units on request from ASTA registered users.
procedure
TForm1.AstaServerSocket1FetchMetaData(Sender: TObject;
ClientSocket: TCustomWinSocket; MetaRequest: TAstaMetaData;
DataBaseStr, Arg1, Arg2: string);
var
i: Integer;
begin
try
case MetaRequest of
mdIndexes, mdPrimeKeys, mdForeignKeys:
begin
LogIt('Index Info for ' + Arg1);
IndexInfoTable.Close;
IndexInfoTable.TableName := Trim(Arg1);
AdjustBDEInfoDatabaseName(DataBaseStr, IndexInfoTable);
IndexInfoTable.Active := True;
if AstaDataSet1.Active then AstaDataSet1.Empty;
AstaDataSet1.CloneFieldsFromDataSet(IndexInfoTable,
False, False);
IndexDataTransfer(IndexInfoTable, AstaDataSet1);
AstaServerSocket1.MetaDataSet := AstaDataSet1;
end;
mdStoredProcColumns:
begin
//ODBC and the BDE create different column names and types.
//When returning param info the BDEInfoToStoredProcAstaInfoTable
//call uses a standard datadet (AstaStoredProcColumnDataSet)
//that the ASTA client.SQLWorkbench can use.
//Other backends need to populate the fields in
//AstaStoredProcColumnDataSet
TableDataSet.Close;
TableDataSet.BDEInfo := BDEStoredProcParams;
AdjustBDEInfoDatabaseName(DataBaseStr, TableDataSet);
TableDataSet.TableName := Arg1;
TableDataSet.Open;
BDEInfoToStoredProcAstaInfoTable(TableDataSet,
AstaStoredProcColumnDataSet);
AstaServerSocket1.MetaDataSet :=
AstaStoredProcColumnDataSet;
LogIt('Stored Proc Param Info for ' + Arg1);
end;
mdStoredProcs:
begin
{$ifdef StoredProcProblemo}
PopulateStoredProcNames;
{$else}
AstaServerSocket1.MetaDataSet := TableDataSet;
TableDataSet.Close;
TableDataSet.BDEInfo := BDEStoredProcedures;
AdjustBDEInfoDatabaseName(DataBaseStr, TableDataSet);
TableDataSet.TableName := '';
TableDataSet.Open;
{$endif}
LogIt('Stored Procedure List');
end;
mdDBMSName:
begin
LogIt('DBMS Info Request');
AstaServerSocket1.MetaDataSet := DBMSDataSet;
end;
mdServerDataSets:
begin
LogIt('Server DataSet Info Request');
AstaServerSocket1.MetaDataSet := ServerDataSets;
end;
else begin
LogIt('Table Info');
TableDataSet.Close;
AdjustBDEInfoDatabaseName(DataBaseStr, TableDataSet);
TableDataSet.TableName := '';
TableDataSet.BDEInfo := BDEOpenTables;
TableDataSet.Open;
AstaServerSocket1.MetaDataSet := TableDataSet;
end;
except
LogException(ClientSocket, 'Stored MetaData Error: ' +
EDataBaseError(ExceptObject).Message, True);
end;
end;