MySQL++ Reference Manual

- Main Page
- 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 Member Functions
| Transaction (Connection &conn, bool consistent=false)
| Constructor.
| ~Transaction ()
| Destructor.
void | commit ()
| Commits the transaction.
void | rollback ()
| Rolls back the transaction.

## Detailed Description

Helper object for creating exception-safe SQL transactions.

## Constructor & Destructor Documentation

Transaction::Transaction | ( | Connection & | conn,
|  | bool | consistent = `false` |
| ) |  |  |

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

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