Get BDE system version information. This function can return the SYSVersion structure or clear and add the information to the SysVerList TStringList. If nil is passed in, only the SYSVersion structure is returned. This example uses the following input:
Ver := fDbiGetSysVersion(MyList);
The function is:
function fDbiGetSysVersion(SysVerList: TStringList): SYSVersion;
var
Month, Day, iHour, iMin, iSec: Word;
Year: SmallInt;
begin
Check(DbiGetSysVersion(Result));
if (SysVerList <> nil) then begin
with SysVerList do begin
Clear;
Add(Format('ENGINE VERSION=%d', [Result.iVersion]));
Add(Format('INTERFACE LEVEL=%d', [Result.iIntfLevel]));
Check(DbiDateDecode(Result.dateVer, Month, Day, Year));
Add(Format('VERSION DATE=%s', [DateToStr(EncodeDate(Year, Month,
Day))]));
Check(DbiTimeDecode(Result.timeVer, iHour, iMin, iSec));
Add(Format('VERSION TIME=%s', [TimeToStr(EncodeTime(iHour, iMin,
Sec div 1000, iSec div 100))]));
end;
end;
end;
//***********************************************************************************
Return the number of open cursors on the specified table. This example uses the following input:
NumCursors := fDbiGetTableOpenCount(InterBaseTable);
The function is:
function fDbiGetTableOpenCount(Table: TTable): Word;
var
Props: CURProps;
begin
Check(DbiGetCursorProps(Table.Handle, Props));
Check(DbiGetTableOpenCount(Table.DBHandle, PChar(Table.TableName),
Props.szTableType, Result));
end;
//***********************************************************************************
Retrieve a description of the capabilities of the table type
The description is appended to the TStringList passed in. This example uses the following input:
fDbiGetTableTypeDesc(szPARADOX, 'PDOX 7.0', MyTableInfo);
fDbiGetTableTypeDesc(szDBASE, 'DBASE5', MyTableInfo);
fDbiGetTableTypeDesc('INTRBASE', 'INTERBASE', MyTableInfo);
The procedure is:
procedure fDbiGetTableTypeDesc(DriverType, TableType: PChar;
var TableTypeInfo: TStringList);
function BoolVal(InBool: Boolean): string;
begin
if InBool then Result:= 'True'
else Result:= 'False';
end;
var
TableTypeRec: TBLType;
begin
Check(DbiGetTableTypeDesc(DriverType, TableType, TableTypeRec));
TableTypeInfo.Add('Table ID: ' + IntToStr(TableTypeRec.iId));
TableTypeInfo.Add('Name: ' + StrPas(TableTypeRec.szName));
TableTypeInfo.Add('Text: ' + StrPas(TableTypeRec.szText));
TableTypeInfo.Add('Format: ' + StrPas(TableTypeRec.szFormat));
TableTypeInfo.Add('User can Read/Write: ' + BoolVal(TableTypeRec.bReadWrite));
TableTypeInfo.Add('Can create new tables: ' + BoolVal(TableTypeRec.bCreate));
TableTypeInfo.Add('Can restructure: ' + BoolVal(TableTypeRec.bRestructure));
TableTypeInfo.Add('Val Checks can be specified: ' + BoolVal(TableTypeRec.bValChecks));
TableTypeInfo.Add('Can be protected: ' + BoolVal(TableTypeRec.bSecurity));
TableTypeInfo.Add('Can participate in ref integrity: ' + BoolVal(TableTypeRec.bRefIntegrity));
TableTypeInfo.Add('Supports primary key concept: ' + BoolVal(TableTypeRec.bPrimaryKey));
TableTypeInfo.Add('Can have other indexes: ' + BoolVal(TableTypeRec.bIndexing));
TableTypeInfo.Add('Number of Phy Field types supported: ' + IntToStr(TableTypeRec.iFldTypes));
TableTypeInfo.Add('Max record size: ' + IntToStr(TableTypeRec.iMaxRecSize));
TableTypeInfo.Add('Max fields in a table: ' + IntToStr(TableTypeRec.iMaxFldsInTable));
TableTypeInfo.Add('Maximum field name length: ' + IntToStr(TableTypeRec.iMaxFldNameLen));
TableTypeInfo.Add('Driver dependent table level (version): ' + IntToStr(TableTypeRec.iTblLevel));
end;
//***************************************************************************************
Obtain information about the Time Format on your system.
This example uses the following input:
Memo1.Lines.Add(fDbiGetTimeFormat);
The function is:
function fDbiGetTimeFormat: string;
var
MyTimeFormat : FMTTime;
begin
Check(DbiGetTimeFormat(MyTimeFormat));
SetLength(Result, 100);
with MyTimeFormat do
Result := Format('Separator: %s, AM: %s, PM: %s',
[cTimeSeparator, szAmString, szPmString]);
SetLength(Result, StrLen(PChar(Result)));
end;
//**************************************************************************************
Get transaction information on the database handle.
This example uses the following input:
fDbiGetTranInfo(Database1.Handle);
The procedure is:
procedure fDbiGetTranInfo(hTmpDb: HDBIDb);
var
xInfoVar: XInfo;
begin
Check(DbiGetTranInfo(hTmpDb, nil, @xInfoVar));
case XInfoVar.eXIL of
xilDIRTYREAD: ShowMessage('Isolation level is Uncommitted changes');
xilREADCOMMITTED: ShowMessage('Isolation level is Committed changes');
xilREPEATABLEREAD: ShowMessage('Isolation level is Full read repeatablity');
end;
end;
//**************************************************************************************
Obtain the first validity check descriptor for the specified cursor.
This example uses the following input:
fDbiGetVchkDesc(hCur, VchkDesc);
The procedure is:
procedure fDbiGetVchkDesc(hCur: hDBICur; var VchkDes: VCHKDesc);
var
CurProp: CURProps;
begin
Check(DbiGetCursorProps(hCur, CurProp));
if (CurProp.iValChecks > 0) then begin
Check(DbiGetVchkDesc(hCur, 1, @VchkDes));
ShowMessage('Field #' + IntToStr(VchkDes.iFldNum) +
' has Validity Checks.');
end
else
MessageDlg(' Validity Check Warning: No validity checks on this table.',
mtError,[MBOK], 0);
end;
//***************************************************************************************
Initialize BDE with default values.
If you have any of the "Data Access" or "Data Controls" VCL components in your project, you should not directly call DbiInit in a Delphi application Those components will automatically call DbiInit.
If you are not using VCL database components, then the following code shows how to initialize the BDE with default values:
Check(dbiInit(nil));
//**************************************************************************************
Append or insert a record on the specified table.
Use the Insert and Post methods on a dataset to insert records. This inserts a new record, contained in pTmpRecBuf, into the table associated with the given cursor. This example uses the following input:
fDbiInsertRecord(hCursor, RecBuf);
The procedure is:
procedure fDbiInsertRecord(hTmpCur: hDBICur; pTmpRecBuf: pByte);
begin
Check(DbiInsertRecord(hTmpCur, dbiNOLOCK, pTmpRecBuf));
end;
Insert or append a record to a table.
If the table has an index, insert the record. Most Delphi users should use: TTable.Insert, TTable.Append, TTable.InsertRecord, or TTable.AppendRecord. This example uses the following input:
fDbiInsertRecord(Table1.Handle, pRecBuf: pBYTE);
The procedure is:
procedure fDbiInsertRecord(hTmpCur: hDBICur; pRec: pBYTE);
var
Props: CURProps;
begin
Check(DbiGetCursorProps(hTmpCur, Props));
// Check to see if there are any active indexes on the table
if (Props.iIndexes > 0) then
// Insert the record
Check(DbiInsertRecord(hTmpCur, dbiNOLOCK, pRec))
else
// Append the record
Check(DbiAppendRecord(hTmpCur, pRec));
end;
//**************************************************************************************
Checks the lock status of the current record.
This example uses the following input:
IsRecordLocked(Table1, True);
NOTE: If ByAnyone is true, then the function also checks if any other session has the record locked. If ByAnyone is false, then only the current session is checked. The function returns False if not locked, and True if locked.
The function is:
function IsRecordLocked(Table: TTable; ByAnyone: Boolean): Boolean;
var
Locked: BOOL;
hCur: hDBICur;
rslt: DBIResult;
begin
Table.UpdateCursorPos;
// Is the record locked by the current session...
Check(DbiIsRecordLocked(Table.Handle, Locked));
Result := Locked;
// If the current session does not have a lock and the ByAnyone varable is
// set to check all sessions, continue check...
if (not Result) and (ByAnyone) then begin
// Get a new cursor to the same record...
Check(DbiCloneCursor(Table.Handle, False, False, hCur));
try
// Try and get the record with a write lock...
rslt := DbiGetRecord(hCur, dbiWRITELOCK, nil, nil);
if (rslt <> DBIERR_NONE) then begin
// if an error occured and it is a lock error, return true...
if (HiByte(rslt) = ERRCAT_LOCKCONFLICT) then
Result := True
else
// If some other error happened, throw an exception...
Check(rslt);
end
else
// Release the lock in this session if the function was successful...
Check(DbiRelRecordLock(hCur, False));
finally
// Close the cloned cursor...
Check(DbiCloseCursor(hCur));
end;
end;
end;
//************************************************************************************
Return the number of locks of type edbiLock aquired on the table passed to the function.
You can obtain table locks by calling the LockTable and UnLockTable methods of the TTable component. This example uses the following input:
LockTotal:= fDbiIsTableLocked(Table1, dbiWRITELOCK);
The function is:
function fDbiIsTableLocked(Tbl: TTable; Lock: DBILockType): Word;
var
NumLocks: Word;
begin
Check(DbiIsTableLocked(Tbl.Handle, Lock, NumLocks));
Result:= NumLocks;
end;
//**************************************************************************************
Load a given driver.
This example uses the following input:
fDbiLoadDriver('PARADOX')
The procedure is:
procedure fDbiLoadDriver(DriverType: string);
begin
Check(DbiLoadDriver(PChar(DriverType)));
end;
//**************************************************************************************
Modify the current record and remove the record lock (if one exists)
Delphi programs should use the Post and Edit methods on a dataset to modify a record. This procedure modifies the current record with the contents of the given record buffer.
procedure fDbiModifyRecord(hCur: hDbiCur; pRecBufModify: pByte);
begin
Check(DbiModifyRecord(hCur, pRecBufModify, True));
end;
//**************************************************************************************