Kea 2.7.6
|
RAII object representing MySQL transaction. More...
#include <mysql_connection.h>
Public Member Functions | |
MySqlTransaction (MySqlConnection &conn) | |
Constructor. | |
~MySqlTransaction () | |
Destructor. | |
void | commit () |
Commits transaction. | |
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.
isc::db::MySqlTransaction::MySqlTransaction | ( | MySqlConnection & | conn | ) |
Constructor.
Starts transaction by making a "START TRANSACTION" query.
conn | MySQL connection to use for the transaction. This connection will be later used to commit or rollback changes. |
DbOperationError | if "START TRANSACTION" query fails. |
Definition at line 41 of file mysql_connection.cc.
References isc::db::MySqlConnection::startTransaction().
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().
void isc::db::MySqlTransaction::commit | ( | ) |
Commits transaction.
Definition at line 55 of file mysql_connection.cc.
References isc::db::MySqlConnection::commit().