ADO Database Delphi

Obtain field types for the driver and append the information to the TStringList passed in.
This example uses the following input:
fDbiOpenFieldTypesList(TmpList, szParadox, 'PDOX 7.0');
The procedure is:
procedure fDbiOpenFieldTypesList(FieldTypeList: TStringList; DrvType, TblType: string);
var
TmpCursor: hDbiCur;
FieldType: FLDType;
result: dbiResult;
begin
Check(DbiOpenFieldTypesList(PChar(DrvType), PChar(TblType), TmpCursor));
FieldTypeList.Clear;
repeat
result:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @FieldType, nil
);
if (result <> DBIERR_EOF) then begin
FieldTypeList.Add('Field Name: ' + FieldType.szName);
end;
until (Result <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//*************************************************************************************
Return a list of files contained within the database.
This example uses the following input:
fDbiOpenFileList(Database1.handle, '*.*', MyFileList);
The procedure is:
procedure fDbiOpenFileList(hDB: hDbiDb; Wild: string; var FileList: TStringList);
var
TmpCursor: hdbicur;
TmpFileDesc: FileDesc;
rslt: dbiResult;
begin
Check(DbiOpenFileList(hDB, PChar(Wild), TmpCursor));
FileList.Clear;
repeat
rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @TmpFileDesc, nil
);
if (rslt <> DBIERR_EOF) then begin
FileList.Add(StrPas(TmpFileDesc.szfilename) + '.' +
StrPas(TmpFileDesc.szext))
end;
until (rslt <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//************************************************************************************
Return a list of indexes on a specific table.
This example uses the following input:
fDbiOpenIndexList(DBASEANIMALS, IndexList);
The procedure is:
procedure fDbiOpenIndexList(Tbl: TTable; var IndexList: TStringList);
var
TmpCursor: hdbicur;
rslt: dbiResult;
IndexDesc: IDXDesc;
begin
Check(DbiOpenIndexList(Tbl.dbhandle, PChar(Tbl.TableName), nil, TmpCursor));
IndexList.Clear;
repeat
rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @IndexDesc, nil);
if (rslt <> DBIERR_EOF) then begin
IndexList.Add(StrPas(IndexDesc.szName))
end;
until (rslt <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//************************************************************************************
Return all language driver information for the system
This example uses the following input:
GetLdList(Memo1.Lines);
The function is defined as follows:
procedure GetLdList(Lines: TStrings);
var
hCur: hDBICur;
LD: LDDesc;
begin
// get a cursor to the in-mem table containing language driver information...
Check(DbiOpenLdList(hCur));
try
while (DbiGetNextRecord(hCur, dbiNOLOCK, @LD, nil) = DBIERR_NONE) do begin
// add the name, code page, and description to the result...
Lines.Add('Name: ' + LD.szName + ' Code Page: ' + IntToStr(LD.iCodePage));
Lines.Add(' Description: ' + LD.szDesc);
end;
finally
Check(DbiCloseCursor(hCur));
end;
end;
//**********************************************************************************
Return a list of locks acquired on a specific table.
This example uses the following input:
fDbiOpenLockList(Table1, LockList);
The procedure is:
procedure fDbiOpenLockList(Tbl: TTable; var LockList: TStringList);
var
TmpCursor: hdbicur;
Lock: LOCKDesc;
rslt: dbiResult;
begin
Check(DbiOpenLockList(Tbl.handle, True, True, TmpCursor));
Check(DbiSetToBegin(TmpCursor));
LockList.Clear;
repeat
rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Lock, nil);
if (rslt <> DBIERR_EOF) then begin
LockList.Add('Lock Type: ' + IntToStr(Lock.iType));
LockList.Add('User Name: ' + StrPas(Lock.szUserName));
LockList.Add('Net Session: ' + IntToStr (Lock.iNetSession));
LockList.Add('Session: ' + IntToStr (Lock.iSession));
LockList.Add('Record Number: ' + IntToStr (Lock.iRecNum));
end;
until (rslt <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//***********************************************************************************
Return all Referential Integrity information in a list for the specified table.
This example uses the following input:
procedure GetRintDesc(Table1, Memo1.Lines)
procedure GetRintDesc(Table: TTable; Lines: TStrings);
var
hCur: hDBICur;
RIDesc: RINTDesc;
rslt: DBIResult;
B: Byte;
Temp: string;
begin
// Get a cursor to the RI information...
Check(DbiOpenRIntList(Table.DBHandle, PChar(Table.TableName), nil, hCur));
try
Lines.Clear;
Check(DbiSetToBegin(hCur));
rslt := DBIERR_NONE;
// While there are no errors, get RI information...
while (rslt = DBIERR_NONE) do begin
// Get the next RI record...
rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @RIDesc, nil);
if (rslt <> DBIERR_EOF) then begin
// Make sure nothing out of the ordinary happened...
Check(rslt);
// Display information...
Lines.Add('RI Number: ' + IntToStr(RIDesc.iRintNum));
Lines.Add('RI Name: ' + RIDesc.szRintName);
case RIDesc.eType of
rintMASTER: Lines.Add('RI Type: MASTER');
rintDEPENDENT: Lines.Add('RI Type: DEPENDENT');
else
Lines.Add('RI Type: UNKNOWN');
end;
Lines.Add('RI Other Table Name: ' + RIDesc.szTblName);
case RIDesc.eModOp of
rintRESTRICT: Lines.Add('RI Modify Qualifier: RESTRICT');
rintCASCADE: Lines.Add('RI Modify Qualifier: CASCADE');
else
Lines.Add('RI Modify Qualifier: UNKNOWN');
end;
case RIDesc.eDelOp of
rintRESTRICT: Lines.Add('RI Delete Qualifier: RESTRICT');
rintCASCADE: Lines.Add('RI Delete Qualifier: CASCADE');
else
Lines.Add('RI Delete Qualifier: UNKNOWN');
end;
Lines.Add('RI Fields in Linking Key: ' + IntToStr(RIDesc.iFldCount));
Temp := '';
for B := 0 to (RIDesc.iFldCount – 1) do
Temp := Temp + IntToStr(RIDesc.aiThisTabFld[B]) + ', ';
SetLength(Temp, Length(Temp) - 2);
Lines.Add('RI Key Field Numbers in Table: ' + Temp);
Temp := '';
for B := 0 to RIDesc.iFldCount - 1 do
Temp := Temp + IntToStr(RIDesc.aiOthTabFld[B]) + ', ';
SetLength(Temp, Length(Temp) - 2);
Lines.Add('RI Key Field Numbers in Other Table: ' + Temp);
Lines.Add('');
end;
end;
finally
// All information was retrieved, close the in-memory table...
Check(DbiCloseCursor(hCur));
end;
end;
//************************************************************************************
Return the record-level security (password) information about a specified Paradox table and append it to the TStringList passed in.
This example uses the following input:
fDbiOpenSecurityList(SecurityTable, SecurityList);
The procedure is:
procedure fDbiOpenSecurityList(Tbl: TTable; SecurityList: TStringList);
var
TmpCursor: hdbicur;
Security: SECDesc;
result: dbiResult;
begin
Check(DbiOpenSecurityList(Tbl.dbhandle, PChar(Tbl.TableName), nil, TmpCursor));
repeat
result:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Security, nil);
if (result <> DBIERR_EOF) then begin
SecurityList.Add('Security Descriptor: ' + IntToStr(Security.iSecNum));
case Security.eprvTable of
prvNone: SecurityList.Add('No privilege');
prvREADONLY: SecurityList.Add('Read only Table or Field');
prvMODIFY: SecurityList.Add('Read and Modify fields (non-key)');
prvINSERT: SecurityList.Add('Insert + All of above');
prvINSDEL: SecurityList.Add('Delete + All of above');
prvFULL: SecurityList.Add('Full Writes');
prvUNKNOWN: SecurityList.Add('Unknown');
end;
SecurityList.Add('Family Rights: ' + IntToStr (Security.iFamRights));
SecurityList.Add('Session: ' + Security.szPassword);
end;
until (Result <> DBIERR_NONE);
Check(DbiCloseCursor(TmpCursor));
end;
//***********************************************************************************
Create a table with information about all tables associated with database.
This example retrieves all tables in the databse with the .DB extension and puts the tablenames into a string list object, such as the Lines property of a TMemo. The example uses the following input:
fDbiOpenTableList(Table1.DBHandle, Memo1.Lines);
The procedure is:
procedure fDbiOpenTableList(hTmpDb: hDBIDb; TableList: TStrings);
var
hCursor : hDBICur;
ListDesc : TBLBaseDesc;
begin
Check(DbiOpenTableList(hTmpDb, False, False, '*.DB', hCursor));
TableList.Clear;
while (DbiGetNextRecord(hCursor, dbiNOLOCK, @ListDesc, nil) = dbiErr_None) do
TableList.Add(ListDesc.szName);
end;
//*************************************************************************************
Display in a MessageBox all table types supported by a driver.
This example uses the following input:
fDbiOpenTableTypesList(szDBASE);
The procedure is:
procedure fDbiOpenTableTypesList(Driver: string);
var
hTypeCur: hDBICur;
TblTypes: TBLType;
BufStr: string;
begin
hTypeCur:= nil;
Check(DbiOpenTableTypesList(PChar(Driver), hTypeCur));
while (DbiGetNextRecord(hTypeCur, dbiNOLOCK, @TblTypes, nil) = DBIERR_NONE) do
begin
BufStr:= format('Name: %s, TableLevel: %d',[Tbltypes.szName,Tbltypes.iTblLevel]);
MessageBox(0, PChar(BufStr), PChar(Driver), MB_OK);
end;
end;