Kea 2.7.5
|
RAII object representing a PostgreSQL transaction. More...
#include <pgsql_connection.h>
Public Member Functions | |
PgSqlTransaction (PgSqlConnection &conn) | |
Constructor. | |
~PgSqlTransaction () | |
Destructor. | |
void | commit () |
Commits transaction. | |
RAII object representing a PostgreSQL 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 PgSqlTransaction::commit is explicitly called or when the instance of this class is destroyed. The PgSqlTransaction::commit commits changes to the database. If the class instance is destroyed before PgSqlTransaction::commit has been called, the transaction is rolled back. The rollback on destruction guarantees that partial data is not stored in the database when an error occurs during any of the operations within a transaction.
By default PostgreSQL performs a commit following each statement which alters the database (i.e. "autocommit"). Starting a transaction stops autocommit for the connection until the transaction is ended by either commit or rollback. Other connections are unaffected.
Definition at line 150 of file pgsql_connection.h.
isc::db::PgSqlTransaction::PgSqlTransaction | ( | PgSqlConnection & | conn | ) |
Constructor.
Starts transaction by executing the SQL statement: "START TRANSACTION"
conn | PostgreSQL connection to use for the transaction. This connection will be later used to commit or rollback changes. |
DbOperationError | if statement execution fails |
Definition at line 114 of file pgsql_connection.cc.
References isc::db::PgSqlConnection::startTransaction().
isc::db::PgSqlTransaction::~PgSqlTransaction | ( | ) |
Destructor.
If the transaction has not been committed, it is rolled back by executing the SQL statement: "ROLLBACK"
DbOperationError | if statement execution fails |
Definition at line 119 of file pgsql_connection.cc.
References isc::db::PgSqlConnection::rollback().
void isc::db::PgSqlTransaction::commit | ( | ) |
Commits transaction.
Commits all changes made during the transaction by executing the SQL statement: "COMMIT"
DbOperationError | if statement execution fails |
Definition at line 127 of file pgsql_connection.cc.
References isc::db::PgSqlConnection::commit().