MySQL++
3.3.0
|
Helper object for creating exception-safe SQL transactions. More...
#include <transaction.h>
Public Types | |
enum | IsolationLevel { read_uncommitted , read_committed , repeatable_read , serializable } |
Transaction isolation levels defined in SQL. More... | |
enum | IsolationScope { this_transaction , session , global } |
Isolation level scopes defined in SQL. More... | |
Public Member Functions | |
Transaction (Connection &conn, bool consistent=false) | |
Simple constructor. More... | |
Transaction (Connection &conn, IsolationLevel level, IsolationScope scope=this_transaction, bool consistent=false) | |
Constructor allowing custom transaction isolation level and scope. More... | |
~Transaction () | |
Destructor. More... | |
void | commit () |
Commits the transaction. More... | |
void | rollback () |
Rolls back the transaction. More... | |
Helper object for creating exception-safe SQL transactions.
Transaction isolation levels defined in SQL.
These values can be passed to one of the Transaction constructors to change the way the database engine protects transactions from other DB updates. These values are in order of increasing isolation, but decreasing performance.
Isolation level scopes defined in SQL.
These values are only used with one of the Transaction constructors, to select which transaction(s) our change to
Enumerator | |
---|---|
this_transaction | change level for this transaction only |
session | change level for all transactions in this session |
global | change level for all transactions on the DB server |
Transaction::Transaction | ( | Connection & | conn, |
bool | consistent = false |
||
) |
Simple constructor.
conn | The connection we use to manage the transaction set |
consistent | Whether to use "consistent snapshots" during the transaction. See the documentation for "START TRANSACTION" in the MySQL manual for more on this. |
References mysqlpp::Query::execute(), and mysqlpp::Connection::query().
Transaction::Transaction | ( | Connection & | conn, |
IsolationLevel | level, | ||
IsolationScope | scope = this_transaction , |
||
bool | consistent = false |
||
) |
Constructor allowing custom transaction isolation level and scope.
conn | The connection we use to manage the transaction set |
level | Isolation level to use for this transaction |
scope | Selects the scope of the isolation level change |
consistent | Whether to use "consistent snapshots" during the transaction. See the documentation for "START TRANSACTION" in the MySQL manual for more on this. |
References mysqlpp::Query::execute(), global, mysqlpp::Connection::query(), read_committed, read_uncommitted, repeatable_read, serializable, and session.
Transaction::~Transaction | ( | ) |
Destructor.
If the transaction has not been committed or rolled back by the time the destructor is called, it is rolled back. This is the right thing because one way this can happen is if the object is being destroyed as the stack is unwound to handle an exception. In that instance, you certainly want to roll back the transaction.
References rollback().
void Transaction::commit | ( | ) |
Commits the transaction.
This commits all updates to the database using the connection we were created with since this object was created. This is a no-op if the table isn't stored using a transaction-aware storage engine. See CREATE TABLE in the MySQL manual for details.
References mysqlpp::Query::execute(), and mysqlpp::Connection::query().
void Transaction::rollback | ( | ) |
Rolls back the transaction.
This abandons all SQL statements made on the connection since this object was created. This only works on tables stored using a transaction-aware storage engine. See CREATE TABLE in the MySQL manual for details.
References mysqlpp::Query::execute(), and mysqlpp::Connection::query().
Referenced by ~Transaction().