{ dbio.pas } program Dbio; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const iNUMDB = 5; {===================================================================== Code: DatabaseIOSample(); Input: None. Return: None. Description: This example shows how to open a number of Databases and get information about those Databases. ===================================================================== } var rslt: DBIResult; { Value returned from IDAPI functions } hDb: array[0..iNUMDB] of hDBIDb; { Array of handles to Databases } hCur: hDBICur; { Handle to the table } TblProps: CURProps; { Properties of the table } szDir: array[0..DBIMAXPATHLEN] of CHAR; { String to hold the directory } szMessage: array[0..100] of CHAR; { String to hold messages } bBlank: BOOL; { Used to determine if a field is blank } iOpenedDatabases: UINT16; { Count of the opened Databases } iLoop: UINT16; { Loop variable } DbDes: DbDesc; { Information about the databases} begin Screen('*** Database Manipulation Example ***'); Screen(' Initializing IDAPI...'); InitOutput; if (ChkRslt(DbiInit(nil), DBIERR_NONE, ' Error - Init.') <> DBIERR_NONE) then { Check if successfull } begin Screen(''); Screen('*** End of Example ***'); CloseOutput; exit; end; { Open up to iNUMDB databases. } for iOpenedDatabases := 0 to iNUMDB-1 do begin Screen(' Open Database# '+IntToStr(iOpenedDatabases+1)); { Open a database } rslt := DbiOpenDatabase('', nil, dbiREADWRITE, dbiOPENSHARED, nil, 0, nil, nil, hDb[iOpenedDatabases]); if (rslt <> DBIERR_NONE) then begin { Know how to deal with running out of Database handles } if (rslt = DBIERR_DBLIMIT) then break; ChkRslt(rslt, DBIERR_NONE, ' Error - OpenDatabase.'); DbiExit; Screen(''); Screen('*** End of Example ***'); CloseOutput; exit; end; end; Screen(''); Screen(' Get the default directory for the first database...'); ChkRslt(DbiGetDirectory(hDb[0], FALSE, szDir), DBIERR_NONE, ' Error - GetDirectory.'); Screen(' The working directory: '+StrPas(szDir)+' '); Screen(' Change the directory which the first database uses...'); ChkRslt(DbiSetDirectory(hDb[0], pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); { Display information about the available databases. Note that this example reads the data from the schema table directly into a structure defined in IDAPI.H. This should only be done with schema tables. } rslt := DbiOpenDatabaseList(hCur); if ( rslt = DBIERR_NONE ) then begin Screen(''); Screen(' Display information about the available databases:'); while (DbiGetNextRecord(hCur, dbiNOLOCK, @DbDes, nil) = DBIERR_NONE) do begin Screen(''); Screen(' Logical Name: '+StrPas(DbDes.szName)+' '); Screen(' Description: '+StrPas(DbDes.szText)+' '); Screen(' Physical name/path: '+StrPas(DbDes.szPhyName)+' '); Screen(' Database type: '+StrPas(DbDes.szDbType)+' '); end; if (rslt <> DBIERR_EOF) then begin ChkRslt(rslt, DBIERR_NONE, ' Error - GetNextRecord.'); end; end; { Place an empty line in the output edit control } Screen(''); { Clean up and return } for iLoop := 0 to iOpenedDatabases do begin Screen(' Close Database# '+IntToStr(iLoop + 1)+' '); { Prepare the message to be displayed in case the closing of the Database fails. } StrPCopy(szMessage, ' Error - Close DB #'+IntToStr(iLoop+1)+' '); rslt := ChkRslt(DbiCloseDatabase(hDb[iLoop]), DBIERR_NONE, szMessage); end; Screen(''); Screen(' Clean up IDAPI'); DbiExit; Screen(''); CloseOutput; Screen('*** End of Example ***'); end.