There are two ways to control transactions through Sybase Open Client Client-Library:
setting isolation levels
using transaction control methods
These techniques are described in the following sections.
You can use the isolation() method of RWDBConnection to set the isolation level of the connection. Table 5 shows the mapping between the RWDBConnection::IsolationType argument you pass and the isolation level set on the connection.
RWDBConnection::IsolationType | Sybase Isolation Level |
Unknown | Level 1 - READ COMMITTED |
ANSILevel1 | Level 1 - READ COMMITTED |
ANSILevel2 | Level 2 - REPEATABLE READ |
ANSILevel3 | Level 3 - SERIALIZABLE |
The current isolation level can be determined by calling the function RWDBConnection::isolation() without an argument.
You can explicitly control transactions through the following methods:
RWDBConnection::beginTransaction(const RWCString& name = RWCString()) RWDBConnection::rollbackTransaction(const RWCString& name = RWCString()) RWDBConnection::commitTransaction(const RWCString& name = RWCString()) RWDBConnection::setSavepoint(const RWCString& name) |
which correspond to:
"begin transaction [name]" "rollback transaction [name]" "commit transaction [name]" "save transaction name" |
An application can add the DB Interface Module transaction methods to its code to take explicit control of its transaction blocks. Transactions may be nested and the savepoint feature is supported. The savepoint feature allows a current transaction to be partially rolled back to a marked point. The following example demonstrates the use of the DB Interface Module savepoint feature and other transaction processing methods.
// Assume we have a table myTable(c int) with no rows in it. RWDBInserter ins = myTable.inserter(); cn.beginTransaction("outmost"); // Begin transaction. // Transaction name is allowed. // Note: unlike savepoint name, // transaction name is not used // by server. (ins << 1).execute(cn); // First insertion cn.beginTransaction("inner"); // Nested transaction begins ... cn.setSavepoint("svp1"); // Save first insertion (ins << 2).execute(cn); // Second insertion (ins << 3).execute(cn); // Third insertion cn.rollbackTransaction("svp1"); // Roll back second and // third insertions. cn.commitTransaction("inner"); // Pairing inner transaction cn.commitTransaction("outmost"); // Commit transaction on // part that is not rolled back. // The above program results in myTable holding one row of data. // Its value is 1. |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.