ADO Database Delphi

Add a password to the current session.
Delphi users should use TSession.AddPassword rather than directly calling dbiAddPassword. The method TSession.AddPassword is defined as:
procedure AddPassword(const Password: string);
The following code adds the password "Hip Hop" to TSession Session:
Session.AddPassword('Hip Hop');
Add a password to the specified handle's session:
Delphi users should use TSession.AddPassword. See DbiGetCurrSession to get the current session's handle. This example uses the following input:
fDbiAddPassword(Session3.Handle, 'SPRINT');
The procedure is defined as:
procedure fDbiAddPassword(hSes: hDBISes; Pswd: string);
begin
Check(DbiSetCurrSession(hSes));
Check(DbiAddPassword(PChar(Pswd)));
end;
//*************************************************************************************
Translate a string from the ANSI character set to the language driver's native character set. This example uses the following input:
fDbiAnsiToNative(CustTbl, string);
The function is defined as:
function fDbiAnsiToNative(Table: TTable; AnsiStr: string): string;
var
pDesc: pLDDesc;
Len: Word;
Done: Boolean;
begin
Len := Length(AnsiStr);
SetLength(Result, Len);
Check(DbiGetLDObj(Table.Handle, pointer(pDesc)));
Check(DbiAnsiToNative(pointer(pDesc), PChar(Result), PChar(AnsiStr), Len, Done));
end;
//************************************************************************************
Append a record to the end of the table associated with the cursor.
Delphi users should use TTable.AppendRecord rather than directly calling dbiAppendRecord. The TTable.AppendRecord method is defined as:
procedure AppendRecord(const Values: array of const);
This statement appends a record to a TTable called Customer. Note that NULL values (using the Pascal nil) are entered for some of the values, but are not required for missing values at the end of the array argument, for example, after the Discount field.
Customer.AppendRecord([CustNoEdit.Text, CoNameEdit.Text, AddrEdit.Text,
nil, nil, nil, nil, nil, nil, DiscountEdit.Text]);
//************************************************************************************
Because the DBIBatchMove function is a complex function that accepts over 20 parameters, Delphi users are often better served by using the VCL component TBatchMove. This component is found on the Data Access page of the Component Palette.
To use the TBatchMove component in your application, set the component's Mode, Mapping, Source, and Destination properties. You can then execute the batch move at design time by right clicking on the component and choosing Execute from the Speed Menu. Or you can execute the function at runtime by calling its Execute method. The following example illustrates using the component at runtime by appending TTables Table1 to Table2:
procedure TForm1.Button1Click(Sender : TObject);
begin
with BatchMove1 do begin
Mode := batAppend;
Source := Table1;
Destination := Table2;
Execute;
end;
end;
Append the source handle's table records to the destination handle's table:
BatchCount is the amount of records to append before committing the transaction. Most Delphi users should use the TBatchMove component or the TTable.BatchMove method. This example uses the following input:
fDbiBatchMove(VendorTbl.Handle, VendorIBTbl.Handle, 500);
The procedure is defined as:
procedure fDbiBatchMove(hSrcCur, hDstCur: hDBICur; BatchCount: Longint);
var
hDb: hDBIDb;
Count: Longint;
Length: Word;
DBType: string;
begin
Count := 0;
// Get the database handle from the destination cursor
Check(DbiGetObjFromObj(hDBIObj(hDstCur), objDATABASE, hDBIObj(hDb)));
SetLength(DBType, DBIMAXNAMELEN);
// Get the database type from the database handle
Check(DbiGetProp(hDBIObj(hDb), dbDATABASETYPE, PChar(DBType), DBIMAXNAMELEN,
Length));
SetLength(DBType, StrLen(PChar(DbType)));
if DBType <> 'STANDARD' then
// If the database is SQL based, set the batch count
Check(DbiSetProp(hDBIObj(hDb), dbBATCHCOUNT, BatchCount));
// Append the records
Check(DbiBatchMove(nil, hSrcCur, nil, hDstCur, batchAPPEND, 0, nil, nil,
nil, 0, nil, nil, nil, nil, nil, nil, True, True, Count, False));
end;
//**********************************************************************************
Create a master/detail link between two tables. The two hDBICur cusrors return linked handles to both tables. Tables must be open on the indexes to link on. This example only supports a 'full index' link; if the link is on a composite index, both tables must link on the complete index. This example uses the following input:
fDbiBeginLinkMode(CustomerTbl, OrdersTbl, hMas, hDet);
The procedure is defined as:
procedure fDbiBeginLinkMode(MasTbl, DetTbl: TTable; var hMasCur,
hDetCur: hDBICur);
var
MasIdxDesc, DetIdxDesc: IDXDesc;
begin
Check(DbiCloneCursor(MasTbl.Handle, False, False, hMasCur));
Check(DbiCloneCursor(DetTbl.Handle, False, False, hDetCur));
Check(DbiGetIndexDesc(hMasCur, 0, MasIdxDesc));
Check(DbiGetIndexDesc(hDetCur, 0, DetIdxDesc));
Check(DbiSetToBegin(hMasCur));
Check(DbiBeginLinkMode(hMasCur));
Check(DbiBeginLinkMode(hDetCur));
Check(DbiLinkDetail(hMasCur, hDetCur, MasIdxDesc.iFldsInKey,
@MasIdxDesc.aiKeyFld, @DetIdxDesc.aiKeyFld));
end;
//************************************************************************************
Start a transaction on the specified database.
Delphi users should use the TDataBase.StartTransaction method rather than directly calling DbiBeginTran. This method is defined as:
procedure TDataBase.StartTransaction;
The following code begins a transaction on a TDataBase object called DataBase1 at the isolation level specified by the TransIsolation property:
DataBase1.StartTransaction;
(Note: If a transaction is currently active, Delphi will raise an exception.)
Start a transaction on a database.
If the database is local, set the transaction isolation level to 'Dirty Read' (the only supported local isolation level). Most Delphi users should use TDatabase.StartTransaction. This example uses the following input:
fDbiBeginTran(Database1.Handle, xilREADCOMMITTED, hTran);
The procedure is defined as:
procedure fDbiBeginTran(hTmpDb: hDBIDb; Mode: eXILType; var hXact: hDBIXact);
var
DBType: string;
W: Word;
begin
SetLength(DBType, DBIMAXNAMELEN);
Check(DbiGetProp(hDBIObj(hTmpDb), dbDATABASETYPE, PChar(DBType),
DBIMAXNAMELEN, W));
SetLength(DBType, StrLen(PChar(DBType)));
// If the transaction is on a local table, make sure it is set to Dirty Read
if (DBType = 'STANDARD') then
Mode := xilDIRTYREAD;
Check(DbiBeginTran(hTmpDb, Mode, hXact));
end;
//***********************************************************************************
Refresh all sessions within the application, if needed. This is a good function to place in a TTimer to refresh data. This example uses the following input:
fDbiCheckRefresh;
The procedure is defined as:
procedure fDbiCheckRefresh;
var
OldSession: TSession;
B: Byte;
begin
OldSession := Sessions.CurrentSession;
for B := 0 to (Sessions.Count – 1) do begin
Sessions.CurrentSession := Sessions.Sessions[B];
Check(DbiCheckRefresh);
end;
Sessions.CurrentSession := OldSession;
end;
//************************************************************************************
Return a new cursor positioned at the first record.
This example uses the following input:
fDbiCloneCursor(Table1.Handle, MyNewCursor);
The procedure is defined as:
procedure fDbiCloneCursor(hTmpCur: hDBICur; var hNewCur: hDBICur);
begin
Check(DbiCloneCursor(hTmpCur, False, False, hNewCur));
Check(DbiSetToBegin(hNewCur));
Check(DbiGetNextRecord(hNewCur, dbiNOLOCK, nil, nil));
end;
//***********************************************************************************
Close the valid cursor passed in:
If you have opened a cursor with a dbi call, then this example applies. Otherwise, use the Close method of a Delphi TDataSet descendent component.
This example uses the following input:
fDbiCloseCursor(hCursor);
The procedure is defined as:
procedure fDbiCloseCursor(phTmpCur: phDBICur);
begin
check(DbiCloseCursor(phTmpCur));
end;
//*************************************************************************************
Close the database associated with the valid handle passed in:
Delphi users should call TDatabase.Close rather than directly calling DbiCloseDatabase. This method is defined as:
procedure TDatabase.Close;
The following code closes a TDatabase component called MyDatabase:
MyDatabase.Close;
Close the database associated with the handle:
Most Delphi users should use TDatabase.Close. This example uses the following input:
fDbiCloseDatabase(hDb);
procedure fDbiCloseDatabase(var hTmpDb: hDBIDb);
begin
Check(DbiCloseDatabase(hTmpDb));
end;
//*********************************************************************************
Close the specified index for this cursor.
This example uses the following input:
fDbiCloseIndex(Table2.Handle, 'SYMBOL');
procedure fDbiCloseIndex(hTmpCur: hDBICur; IndexName: string);
begin
Check(DbiCloseIndex(hTmpCur, PChar(IndexName), 0));
end;
//********************************************************************************
Close the current session.
Delphi users should use TSession.Close rather than directly calling dbiCloseSession. The method TSession.Close is defined as:
procedure TSession.Close;
The following code closes TSession Session:
Session.Close;
Close the session associated with the handle.
Most Delphi users should use Session.Close or the TSession component. This example uses the following input:
DbiCloseSession(hSes);
procedure fDbiCloseSession(hTmpSes: hDBISes);
begin
Check(DbiCloseSession(hTmpSes));
end;