MySQL++  3.3.0
Public Types | Public Member Functions | List of all members
mysqlpp::Transaction Class Reference

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...
 

Detailed Description

Helper object for creating exception-safe SQL transactions.

Member Enumeration Documentation

◆ IsolationLevel

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.

Enumerator
read_uncommitted 

allow "dirty reads" from other transactions

read_committed 

only read rows committed by other transactions

repeatable_read 

other transactions do not affect repeated reads in this transaction

serializable 

this transaction prevents writes to any rows it accesses while it runs

◆ IsolationScope

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

Constructor & Destructor Documentation

◆ Transaction() [1/2]

Transaction::Transaction ( Connection conn,
bool  consistent = false 
)

Simple constructor.

Parameters
connThe connection we use to manage the transaction set
consistentWhether 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() [2/2]

Transaction::Transaction ( Connection conn,
IsolationLevel  level,
IsolationScope  scope = this_transaction,
bool  consistent = false 
)

Constructor allowing custom transaction isolation level and scope.

Parameters
connThe connection we use to manage the transaction set
levelIsolation level to use for this transaction
scopeSelects the scope of the isolation level change
consistentWhether 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::~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().

Member Function Documentation

◆ commit()

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().

◆ rollback()

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().


The documentation for this class was generated from the following files: