Kea 2.7.6
isc::db::MySqlTransaction Class Reference

RAII object representing MySQL transaction. More...

#include <mysql_connection.h>

+ Inheritance diagram for isc::db::MySqlTransaction:

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
connMySQL connection to use for the transaction. This connection will be later used to commit or rollback changes.
Exceptions
DbOperationErrorif "START TRANSACTION" query fails.

Definition at line 41 of file mysql_connection.cc.

References isc::db::MySqlConnection::startTransaction().

+ Here is the call graph for this function:

◆ ~MySqlTransaction()

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

Destructor.

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

Definition at line 46 of file mysql_connection.cc.

References isc::db::MySqlConnection::rollback().

+ Here is the call graph for this function:

Member Function Documentation

◆ commit()

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

Commits transaction.

Definition at line 55 of file mysql_connection.cc.

References isc::db::MySqlConnection::commit().

+ Here is the call graph for this function:

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