Using Transaction Control Methods
You can explicitly control transactions through the following methods:
 
RWDBConnection::beginTransaction()
RWDBConnection::rollbackTransaction()
RWDBConnection::commitTransaction()
These methods have straightforward implementations that correspond to the following ODBC functions:
 
SQLSetConnectAttr(SQLHDBC, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, 0)
SQLEndTran(SQL_HANDLE_DBC, SQLHDBC, SQL_ROLLBACK)
SQLSetConnectAttr(SQLHDBC, SQL_ATTR_AUTOCOMMIT,
SQL_AUTOCOMMIT_ON, 0)
 
An application can add the DB Interface Module transaction methods to its code to take explicit control of its transaction blocks. The following code demonstrates how these methods can be used to commit or to rollback transactions:
 
// Assume we have a table myTable(c int) with no rows in it.
RWDBInserter ins = myTable.inserter();
 
cn1.beginTransaction(); // Begin transaction
 
(ins << 1).execute(cn1); // First insertion
...
cn1.commitTransaction(); // Save first insertion
 
cn1.beginTransaction(); // Begin another transaction
(ins << 2).execute(cn1); // Second insertion
(ins << 3).execute(cn1); // Third insertion
cn1.rollbackTransaction(); // Rollback transaction erasing
// second and third insertions
 
// The above program results in myTable holding one row of data.
// Its value is 1.
 
NOTE: Note that ODBC does not support nested transactions and savepoint features.
Attempting to create a nested transaction generates a server error. Attempting to use the savepoint features of the DB Interface Module API generates the error RWDBStatus::notSupported for the connection that tried.