Transactions

<< Click to Display Table of Contents >>

Navigation:  The Vo2Ado RDD > Basics >

Transactions

Previous pageReturn to chapter overviewNext page

The Vo2ADO RDD has built-in support for transactions, and uses the transaction related methods on the AdoConnection object.

We have added 4 special DbInfo() constants that allow you to do so:

 

DBI_BEGINTRANS (DBI_USER + 9)Start transaction on current connection
DBI_ROLLBACKTRANS (DBI_USER + 10)Rollback transaction on current connection
DBI_COMMITTRANS (DBI_USER + 11)Commit transaction on current connection
DBI_HASTRANS (DBI_USER + 12)Does the connection have a transaction active ?

 

Some issues related to transactions

Since connections in ADO involve all tables opened through the same connection, you should always use the same connection when you want to embed multiple tables in an application in a single transaction. That means that the tables should have the same Connection name or no connection name (because hen we use the name DEFAULT)

A second thing to remember is that pending changes are discarded if you close a table before you have rolled back or committed the transaction.

Please be careful when using transactions in combination with relations: ADO does not allow to close recordsets while a transaction is pending. If you are using (selective) relations every skip in the parent table will cause a new child recordset to be opened. If you do this with a pending transaction the old recordsets will be kept open by the RDD, which may cost valuable resources.

 

A sample:

 

 LOCAL oError AS USUAL

 LOCAL cbErr  AS CODEBLOCK

 cbErr := ErrorBlock({|oErr|_Break(oErr)})

 BEGIN SEQUENCE

         USE PUBS::AUTHORS                        

         GO TOP                                // Open the table

         DBINFO(DBI_BEGINTRANS )                // Start transaction

         DO WHILE .NOT. EOF()

                 AUTHORS->SALARY := AUTHORS->SALARY+10

                 SKIP

         ENDDO

         DBINFO(DBI_COMMITTRANS)                // Commit

 RECOVER USING oError

         // Error could have occurred before the BEGINTRANS

         IF DBINFO(DBI_HASTRANS)                

                 DBINFO(DBI_ROLLBACKTRANS)

         ENDIF

         MyErrorHandler(oError)

 END

 ErrorBlock(cbErr)

 USE