MySQL++ Reference Manual

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

# mysqlpp::Transaction Class Reference

Helper object for creating exception-safe SQL transactions. More...

`#include <transaction.h>`

Collaboration diagram for mysqlpp::Transaction:

[legend]
List of all members.

## Public Types
| 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
| 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
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.
| Transaction (Connection &conn, IsolationLevel level, IsolationScope scope=this_transaction, bool consistent=false)
| Constructor allowing custom transaction isolation level and scope.
| ~Transaction ()
| Destructor.
void | commit ()
| Commits the transaction.
void | rollback ()
| Rolls back the transaction.

## Detailed Description

Helper object for creating exception-safe SQL transactions.

## Member Enumeration Documentation

enum mysqlpp::Transaction::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

enum mysqlpp::Transaction::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::Transaction | ( | Connection & | conn,
|  | bool | consistent = `false` |
| ) |  |  |

Simple constructor.

Parameters:

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

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

Constructor allowing custom transaction isolation level and scope.

Parameters:

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

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.

## Member Function Documentation

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.

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.

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

- transaction.h
- transaction.cpp