- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

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

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.

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.

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.

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

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

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

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

- transaction.h
- transaction.cpp