Delphi Examples: DbiBeginTran

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiBeginTran

Return to chapter overview

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;