{ drvcaps.pas } program DrvCaps; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} {===================================================================== Function: YesOrNo (bTemp: Bool) Input: bTemp - A Boolean Variable Return: PChar - Either a Yes or a No. Description: Depending upon the value of the input varaible, this fiunction returns a 'Yes' if True and 'No' if False. ===================================================================== } function YesOrNo(bTemp: Bool): String; begin if (bTemp) then YesOrNo := 'Yes' else YesOrNo := 'No'; end; {===================================================================== Function: DisplayOptionalParams (pCHAR szDriver) Input: szDriver - name of the driver Return: DBIResult - result of the operation Description: This function is used to display the Optional Parameters for a given driver. ===================================================================== } function DisplayOptionalParams (szDriver: pCHAR): DBIResult; var rslt: DBIResult; { Return value from IDAPI functions } hCur: hDBICur; { Handle to the Cursor } szNode: pCHAR; { String which contains the name of the node } CfgDesc: pCFGDesc; { Configuration Descriptor } szCfgPath: array[0..DBIMAXPATHLEN + 1] of CHAR; { Maximum length of the path in the configuration file. } szFieldNames: pCHAR; { String to contain the field names } szFieldValues: pCHAR; { String to contain the field values } begin { Set up the option to get from the Configuration File } StrCopy(szCfgPath, '\DRIVERS\'); StrCat(szCfgPath, szDriver); StrCat(szCfgPath, '\TABLE CREATE\'); { Open the Configuration file - returns the configuration options for the current level in a schema table referenced by hCur. } rslt := ChkRslt(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPersistent, szCfgPath, hCur), DBIERR_NONE, ' Error - OpenCfgInfoList.'); if (rslt <> DBIERR_NONE) then begin DisplayOptionalParams := rslt; exit; end; { Allocate resources } GetMem(szNode, DBIMAXPATHLEN * sizeof(CHAR) + 1); GetMem(szFieldNames, DBIMAXSCRECSIZE * sizeof(CHAR) + 1); GetMem(szFieldValues, DBIMAXSCRECSIZE * sizeof(CHAR) + 1); GetMem(CfgDesc, sizeof(CFGDesc)); { Set the spacing } StrCopy(szFieldNames, ' '); StrCopy(szFieldValues, ' '); { Process all nodes Get the next record in the table - contains the next option of the given level in the tree. } while (DbiGetNextRecord(hCur, dbiNOLOCK, pBYTE(CfgDesc), nil) = DBIERR_NONE) do begin { Output this node, copying the name of the node to the szNode variable. } StrCopy(szNode, RightPad(szNode, CfgDesc^.szNodeName, 16)); StrCat(szFieldNames, szNode); { Display the remaining information Display the Description of the node } StrCopy(szNode, RightPad(szNode, CfgDesc^.szValue, 16)); StrCat(szFieldValues, szNode); end; { Diplay the field names and values } Screen(StrPas(szFieldNames)); Screen(StrPas(szFieldValues)); { Clean up } FreeMem(szNode, DBIMAXPATHLEN * sizeof(CHAR) + 1); FreeMem(szFieldNames, DBIMAXSCRECSIZE * sizeof(CHAR) + 1); FreeMem(szFieldValues, DBIMAXSCRECSIZE * sizeof(CHAR) + 1); FreeMem(CfgDesc, sizeof(CFGDesc)); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); DisplayOptionalParams := rslt; end; {===================================================================== Code: DriverCaps(); Description: This example shows how to determine the capabilities of available IDAPI drivers. This includes the Table types supported and the fields which those Table Types support. ===================================================================== } var hDb: hDBIDb; { Handle to the Database } hDrvCur: hDBICur; { Handle to the in-memory table containing the driver list } hTblTypeCur: hDBICur; { Handle to the in-memory table containing the table-type list } hFldTypeCur: hDBICur; { Handle to the in-memory table containing the field-type list } hIdxTypeCur: hDBICur; { Handle to the in-memory table containing the index-type list } rslt: DBIResult; { Return value from IDAPI functions } TblProps: CURProps; { Table Properties } pRecBuf: pBYTE; { Record Buffer } szDriver: array[0..DBIMAXNAMELEN+1] of CHAR; { String to contain the driver name } szTempBuf: array[0..DBIMAXMSGLEN+1] of CHAR; bIsBlank: BOOL; { Is the field blank? } drType: DRVType; { Driver type information } begin Screen('*** Driver Capabilities Example ***'); Screen(' Initializing IDAPI...'); if (InitAndConnect(hDb) <> DBIERR_NONE) then { Terminate example if } begin { Initialization fails } Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Setting the default Database directory... '); ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - DbSetDirectory.'); { Get a list of the drivers which are available to the system (drivers which have an alias defined within the configuration file) } rslt := ChkRslt(DbiOpenDriverList(hDrvCur), DBIERR_NONE, ' Error - OpenDriverList.'); if (rslt <> DBIERR_NONE) then begin CloseDbAndExit(hDb); Screen(''); Screen('*** End of example ***'); exit; end; { Get the size of the record buffer } ChkRslt(DbiGetCursorProps(hDrvCur, TblProps), DBIERR_NONE, ' Error - GetProps.'); { Allocate space for the Record Buffer } GetMem(pRecBuf, TblProps.iRecBufSize * sizeof(BYTE)); if not Assigned(pRecBuf) then begin Screen(' Error - Could not allocate memory.'); ChkRslt(DbiCloseCursor(hDrvCur), DBIERR_NONE, ' Error - CloseCursor.'); CloseDbAndExit(hDb); Screen(''); Screen('*** End of example ***'); exit; end; Screen(' Go to the beginning of the table...'); ChkRslt(DbiSetToBegin(hDrvCur), DBIERR_NONE, ' Error - SetToBegin.'); { Iterate through all available drivers in the configuration file. } while (DbiGetNextRecord(hDrvCur, dbiNoLock, pRecBuf, nil) = DBIERR_NONE) do begin { Get the name of the Driver } ChkRslt(DbiGetField(hDrvCur, 1, pRecBuf, @szDriver, bIsBlank), DBIERR_NONE, ' Error - GetField.'); { Limit driver information to local tables (the edit control can only hold so much....) } if ((StrComp(szDriver, szPARADOX) = 0) or (StrComp(szDriver, szDBASE) = 0) ) then begin Screen(''); { Get the description of the driver } rslt := ChkRslt(DbiGetDriverDesc(szDriver, drType), DBIERR_NONE, ' Error - GetDriverDesc.'); if (rslt <> DBIERR_NONE) then begin continue; end; { Display the information about the driver } Screen(' Driver Name: '+ ' '+StrPas(drType.szType)+' '); Screen(' Description: '+ ' '+StrPas(drType.szText)+' '); { Create a string to display depending on the Driver category } case (drType.edrvCat) of drvFILE: StrCopy(szTempBuf, 'FILE Based (PDox, dBASE, Text)'); drvOTHERSERVER: StrCopy(szTempBuf, 'Other type of server???'); drvSQLBASEDSERVER: StrCopy(szTempBuf, 'SQL Based Server'); end; Screen(' Category: '+ ' '+StrPas(szTempBuf)+' '); Screen(' Supports true database concepts: '+ YesOrNo(drType.bTrueDb)); Screen(' Database type to use: '+ ' '+StrPas(drType.szDbType)+' '); Screen(' Supports multi-user: '+ YesOrNo(drType.bMultiUser)); Screen(' Read only?: '+ YesOrNo(not (drType.bReadWrite))); Screen(' Transaction support: '+ YesOrNo(drType.bTrans)); Screen(' Supports pass-through SQL: '+ YesOrNo(drType.bPassThruSQL)); Screen(' Requires explicit login: '+ YesOrNo(drType.bLogIn)); Screen(' Can create a database: '+ YesOrNo(drType.bCreateDb)); Screen(' Can drop a database: '+ YesOrNo(drType.bDeleteDb)); Screen(' Can create a table: '+ YesOrNo(drType.bCreateTable)); Screen(' Can delete a table: '+ YesOrNo(drType.bDeleteTable)); Screen(' Multiple passwords: '+ YesOrNo(drType.bMultiplePWs)); { Determine table types that the driver can use } rslt := ChkRslt(DbiOpenTableTypesList(szDriver, hTblTypeCur), DBIERR_NONE, ' Error - OpenTableTypesList.'); if (rslt <> DBIERR_NONE) then begin continue; end; Screen(''); Screen(' Table types supported by the driver...'); DisplayInMemoryTable(hTblTypeCur, 0); ChkRslt(DbiCloseCursor(hTblTypeCur), DBIERR_NONE, ' Error - CloseCursor.'); { Determine field types that the driver can use } rslt := ChkRslt(DbiOpenFieldTypesList(szDriver, nil, hFldTypeCur), DBIERR_NONE, ' Error - OpenFieldTypesList.'); if (rslt <> DBIERR_NONE) then begin continue; end; Screen(''); Screen(' Field types supported by the driver...'); DisplayInMemoryTable(hFldTypeCur, 0); ChkRslt(DbiCloseCursor(hFldTypeCur), DBIERR_NONE, ' Error - CloseCursor.'); { Determine Index types that the driver can use } rslt := ChkRslt(DbiOpenIndexTypesList(szDriver, hIdxTypeCur), DBIERR_NONE, ' Error - OpenTableTypesList.'); if (rslt <> DBIERR_NONE) then begin continue; end; Screen(''); Screen(' Display the Index types that the driver'+ ' supports...'); DisplayInMemoryTable(hIdxTypeCur, 0); ChkRslt(DbiCloseCursor(hIdxTypeCur), DBIERR_NONE, ' Error - CloseCursor.'); Screen(''); Screen(' Optional Parameters....'); Screen(''); DisplayOptionalParams (drType.szType); end; end; FreeMem(pRecBuf, TblProps.iRecBufSize * sizeof(BYTE)); ChkRslt(DbiCloseCursor(hDrvCur), DBIERR_NONE, ' Error - CloseCursor.'); Screen(''); Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen('*** End of Example ***'); end.