ADO Database Delphi

Returns a handle to an in-memory table listing all the nodes in the configuration file accessible by the specified path.
WARNING: Be extremely careful when altering the IDAPI.CFG configuration file. Make absolutely sure that all options and parameters are correct or corruption of the configuration file can, and more than likely, occur.
Example 1: Retrieve a particular value from the IDAPI.CFG configuration file.
This example uses the following input:
Edit1.Text := GetConfigParameter(PARADOXLEVEL, @Count);
NOTE: Param (in this case PARADOXLEVEL) must be a string that contains the path to the node and the node item separated by a semi-colon. At the bottom of this page are some of the more popular paths and items that are declared as constants for use with all these examples.
The function is:
function GetConfigParameter(Param: string; Count: pword): string
;
var
hCur: hDBICur;
rslt: DBIResult;
Config: CFGDesc;
Path, Option: string;
Temp: array[0..255] of char;
begin
Result := '';
hCur := nil;
if (Count <> nil) then
Count^ := 0;
try
if (Pos(';', Param) = 0) then
raise EDatabaseError.Create('Invalid parameter passed to' +
'function. There must be a semi-colon delimited sting passed');
Path := Copy(Param, 0, Pos(';', Param) - 1);
Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', Param));
Check(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPERSISTENT,
StrPCopy(Temp, Path), hCur));
Check(DbiSetToBegin(hCur));
repeat
rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);
if (rslt = DBIERR_NONE) then begin
if (StrPas(Config.szNodeName) = Option) then
Result := Config.szValue;
if (Count <> nil) then
Inc(Count^);
end
else
if (rslt <> DBIERR_EOF) then
Check(rslt);
until (rslt <> DBIERR_NONE);
finally
if (hCur <> nil) then
Check(DbiCloseCursor(hCur));
end;
end;
//*************************************************************************************
Example 1: Open a local database:
procedure fDbiOpenDatabase1(var hDb: hDbiDb; Alias: String);
begin
Check(DbiOpenDatabase(PChar(Alias), nil, dbiReadWrite, dbiOpenShared,
nil, 0, nil, nil, hdb));
end;
Example 2: Open a NULL database (for in-memory or temp tables)
Set the directory for the tables (temp tables only).
procedure fDbiOpenDatabase2(var hDb: hDbiDb; Directory: string);
begin
Check(DbiOpenDatabase(nil, nil, dbiREADWRITE, dbiOPENSHARED,
nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Directory)));
end;
Example 3: Open a remote database with alias and password.
procedure fDbiOpenDatabase3(var hDb: hDbiDb; Alias, Password: string);
begin
Check(DbiOpenDatabase(PChar(Alias), nil, dbiREADWRITE, dbiOPENSHARED,
PChar(Password), 0, nil, nil, hDb));
end;
Example 4: Open a database with a user name other than the one specified in the BDE configuration.
This example uses the following input:
fDbiOpenDatabase3(hDb, 'IBLOCAL', 'sysdba', 'speedy');
The procedure is:
procedure fDbiOpenDatabase3(var hTmpDb: hDBIDb; Alias, UserName, Password: string);
var
Options: FLDDesc;
begin
FillChar(Options, sizeof(Options), #0);
Options.iOffset := 0;
Options.iLen := Length(UserName) + 1;
StrPCopy(Options.szName, 'USER NAME');
Check(DbiOpenDatabase(PChar(Alias), nil, dbiREADWRITE, dbiOPENSHARED,
PChar(Password), 1, @Options, PChar(UserName), hTmpDb));
end;
//**************************************************************************************
Return a list of of accessible databases and all aliases found in the configuration file.
This example uses the following input:
fDbiOpenDatabaseList(DatabaseList);
The procedure is:
procedure fDbiOpenDatabaseList(DatabaseList: TStringList);
var
TmpCursor: hDbiCur;
Database: DBDesc;
rslt: DbiResult;
begin
DatabaseList.Clear;
Check(DbiOpenDatabaseList(TmpCursor));
repeat
rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Database, nil);
if (rslt <> DBIERR_EOF) then begin
DatabaseList.Add(StrPas(Database.szName)
+ ' - ' + StrPas(Database.szPhyName)
+ ' - ' + StrPas(Database.szDbType))
end;
until (rslt <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//*************************************************************************************
Return a list of driver names available to the client application.
This example uses the following input:
fDbiOpenDriverList(DriverList);
The procedure is:
procedure fDbiOpenDriverList(var DriverList: TStringList);
var
TmpCursor: hdbicur;
Driver: DRVType;
rslt: dbiResult;
begin
Check(DbiOpenDriverList(TmpCursor));
DriverList.Clear;
repeat
rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Driver, nil);
if (rslt <> DBIERR_EOF) then begin
DriverList.Add(StrPas(Driver.szType))
end;
until rslt <> DBIERR_NONE;
Check(DbiCloseCursor(TmpCursor));
end;
//**************************************************************************************
his example uses the following input:
fDbiOpenFieldList(Table1, True, Memo1.Lines);
The procedure is:
procedure fDbiOpenFieldList(Table: TTable; Physical: Boolean; List: TStrings);
function BDEFieldIntToStr(FieldType: Word): string;
begin
case FieldType of
fldUNKNOWN: result := 'unknown';
fldZSTRING: result := 'string'; { Null terminated string }
fldDATE: result := 'date'; { Date (32 bit) }
fldBLOB: result := 'BLOb'; { Blob }
fldBOOL: result := 'boolean'; { Boolean (16 bit) }
fldINT16: result := 'integer'; { 16 bit signed number }
fldINT32: result := 'long integer'; { 32 bit signed number }
fldFLOAT: result := 'float'; { 64 bit floating point }
fldBCD: result := 'BCD'; { BCD }
fldBYTES: result := 'bytes'; { Fixed number of bytes }
fldTIME: result := 'time'; { Time (32 bit) }
fldTIMESTAMP: result := 'timestamp'; { Time-stamp (64 bit) }
fldUINT16: result := 'unsigned int'; { Unsigned 16 bit integer }
fldUINT32: result := 'unsigned long int'; { Unsigned 32 bit integer }
fldFLOATIEEE: result := 'float IEEE'; { 80-bit IEEE float }
fldVARBYTES: result := 'varbytes'; { Length prefixed var bytes }
fldLOCKINFO: result := 'lockinfo'; { Look for LOCKINFO typedef }
fldCURSOR: result := 'Oracle cursor'; { For Oracle Cursor type }
{ Paradox types (Physical) }
fldPDXCHAR: result := 'alpha'; { Alpha (string) }
fldPDXNUM: result := 'numeric'; { Numeric }
fldPDXMONEY: result := 'money'; { Money }
fldPDXDATE: result := 'date'; { Date }
fldPDXSHORT: result := 'smallint'; { Short }
fldPDXMEMO: result := 'Memo BLOb'; { Text Memo (blob) }
fldPDXBINARYBLOB: result := 'Binary BLOb'; { Binary data (blob) }
fldPDXFMTMEMO: result := 'formatted BLOb'; { Formatted text (blob) }
fldPDXOLEBLOB: result := 'OLE BLOb'; { OLE object (blob) }
fldPDXGRAPHIC: result := 'Graphic BLOb'; { Graphics object (blob) }
fldPDXLONG: result := 'long integer'; { Long }
fldPDXTIME: result := 'time'; { Time }
fldPDXDATETIME: result := 'date time'; { Time Stamp }
fldPDXBOOL: result := 'boolean'; { Logical }
fldPDXAUTOINC: result := 'auto increment'; { Auto increment (long) }
fldPDXBYTES: result := 'bytes'; { Fixed number of bytes }
fldPDXBCD: result := 'BCD'; { BCD (32 digits) }
{ xBASE types (Physical) }
fldDBCHAR: result := 'character'; { Char string }
fldDBNUM: result := 'number'; { Number }
fldDBMEMO: result := 'Memo BLOb'; { Memo (blob) }
fldDBBOOL: result := 'logical'; { Logical }
fldDBDATE: result := 'date'; { Date }
fldDBFLOAT: result := 'float'; { Float }
fldDBLOCK: result := 'LOCKINFO'; { Logical type is LOCKINFO }
fldDBOLEBLOB: result := 'OLE BLOb'; { OLE object (blob) }
fldDBBINARY: result := 'Binary BLOb'; { Binary data (blob) }
fldDBBYTES: result := 'bytes'; { Only for TEMPORARY tables }
fldDBLONG: result := 'long integer'; { Long (Integer) }
fldDBDATETIME: result := 'date time'; { Time Stamp }
fldDBDOUBLE: result := 'double'; { Double }
fldDBAUTOINC: result := 'aut increment'; { Auto increment (long) }
else
Result := 'not found';
end;
end;
var
hFieldCur: hDBICur;
rslt: DBIResult;
Field: FLDDesc;
begin
List.Clear;
Check(DbiOpenFieldList(Table.DBHandle, PChar(Table.TableName), nil,
Physical, hFieldCur));
repeat
rslt := DbiGetNextRecord(hFieldCur, dbiNOLOCK, @Field, nil);
if (rslt = DBIERR_NONE) then begin
List.Add(Format('Field #%d) Name:%s Type:%s', [Field.iFldNum,
Field.szName, BDEFieldIntToStr(Field.iFldType)]));
end;
until (rslt <> DBIERR_NONE);
end;