Using Transaction Control Methods
You can explicitly control transactions through the following methods:
 
RWDBConnection::beginTransaction()
RWDBConnection::rollbackTransaction(const RWCString& name = RWCString())
RWDBConnection::commitTransaction()
RWDBConnection::setSavepoint(const RWCString& name)
These methods have straightforward implementations that correspond to the following MySQL calls:
 
START TRANSACTION
ROLLBACK
ROLLBACK TO SAVEPOINT name
COMMIT
SAVEPOINT name
NOTE: These transaction calls have the desired affect only when used with transaction-safe tables such as those created with the InnoDB storage engine.
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.
Example 3 – Using Transaction Control Methods
// Assume we have a table myTable(c int) with no rows in it.
RWDBInserter ins = myTable.inserter();
 
cn.beginTransaction(); // Begin transaction..
 
(ins << 1).execute(cn); // First insertion
 
cn.setSavepoint("svpt"); // Save first insertion
 
(ins << 2).execute(cn); // Second insertion
(ins << 3).execute(cn); // Third insertion
cn.rollbackTransaction("svpt"); // Rollback transaction erasing
// second and third insertions.
cn.commitTransaction(); // commit transaction on part
// that is not rolled back
 
// The above program results in myTable holding one row of data.
// Its value is 1.
 
NOTE: DB Access Module for MySQL does not support nested transactions.