tntdb::Transaction Class Reference

The class Transaction monitors the state of a transaction on a database connection. More...

`#include <transaction.h>`

## Public Member Functions

| Transaction (const Connection &db_, bool starttransaction=true)
| Create a Transaction object.
| ~Transaction ()
| Roll back transaction if still active.
const Connection & | getConnection () const
Connection & | getConnection ()
void | begin ()
| Start a new transaction. If there is an active transaction, it is rolled back first.
void | commit ()
| Commit the current transaction.
void | rollback ()
| Roll back the current transaction.
void | lockTable (const std::string &tableName, bool exclusive=true)
| Lock the specified table.

## Detailed Description

The class Transaction monitors the state of a transaction on a database connection.

The constructor by default starts a transaction on the database. The transaction state is held in the class. The destructor rolls back the transaction if it isn't explicitely commited or rolled back.

## Constructor & Destructor Documentation

## Transaction()

tntdb::Transaction::Transaction | ( | const Connection & | db_,
|  | bool | starttransaction = true )

Create a Transaction object.

## ~Transaction()

tntdb::Transaction::~Transaction | ( |  | ) |

Roll back transaction if still active.

## Member Function Documentation

## begin()

void tntdb::Transaction::begin | ( |  | ) |

Start a new transaction. If there is an active transaction, it is rolled back first.

## commit()

void tntdb::Transaction::commit | ( |  | ) |

Commit the current transaction.

If there is no active transaction, nothing is done. The transaction state is reset.

## lockTable()

void tntdb::Transaction::lockTable | ( | const std::string & | tableName,
|  | bool | exclusive = true )

Lock the specified table.

Locks are released when the transaction is committed or rolled back either explicitly or implicitly by the destructor.

## rollback()

void tntdb::Transaction::rollback | ( |  | ) |

Roll back the current transaction.

If there is no active transaction, nothing is done. The transaction state is reset.

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

- tntdb/transaction.h