| Kea 3.0.2-git

isc::db::MySqlTransaction Class Reference

RAII object representing MySQL transaction. More...

`#include <mysql_connection.h>`

Inheritance diagram for isc::db::MySqlTransaction:
[legend]

## Public Member Functions
| MySqlTransaction (MySqlConnection &conn)
| Constructor.
| ~MySqlTransaction ()
| Destructor.
void | commit ()
| Commits transaction.

## Detailed Description

RAII object representing MySQL transaction.

An instance of this class should be created in a scope where multiple INSERT statements should be executed within a single transaction. The transaction is started when the constructor of this class is invoked. The transaction is ended when the MySqlTransaction::commit is explicitly called or when the instance of this class is destroyed. The MySqlTransaction::commit commits changes to the database and the changes remain in the database when the instance of the class is destroyed. If the class instance is destroyed before the MySqlTransaction::commit is called, the transaction is rolled back. The rollback on destruction guarantees that partial data is not stored in the database when there is an error during any of the operations belonging to a transaction.

The default MySQL backend configuration enables 'autocommit'. Starting a transaction overrides 'autocommit' setting for this particular transaction only. It does not affect the global 'autocommit' setting for the database connection, i.e. all modifications to the database which don't use transactions will still be auto committed.

Definition at line 194 of file mysql_connection.h.

## Constructor & Destructor Documentation

## ◆ MySqlTransaction()

isc::db::MySqlTransaction::MySqlTransaction | ( | MySqlConnection & | conn | ) |

Constructor.

Starts transaction by making a "START TRANSACTION" query.

Parameters

  conn | MySQL connection to use for the transaction. This connection will be later used to commit or rollback changes.

Exceptions

  DbOperationError | if "START TRANSACTION" query fails.

Definition at line 43 of file mysql_connection.cc.

## ◆ ~MySqlTransaction()

isc::db::MySqlTransaction::~MySqlTransaction | ( |  | ) |

Destructor.

Rolls back the transaction if changes haven't been committed.

Definition at line 48 of file mysql_connection.cc.

## Member Function Documentation

## ◆ commit()

void isc::db::MySqlTransaction::commit | ( |  | ) |

Commits transaction.

Definition at line 57 of file mysql_connection.cc.

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

- mysql_connection.h
- mysql_connection.cc