Kea 2.5.9
isc::db::PgSqlTransaction Class Reference

RAII object representing a PostgreSQL transaction. More...

#include <pgsql_connection.h>

+ Inheritance diagram for isc::db::PgSqlTransaction:

Public Member Functions

 PgSqlTransaction (PgSqlConnection &conn)
 Constructor.
 
 ~PgSqlTransaction ()
 Destructor.
 
void commit ()
 Commits transaction.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PgSqlTransaction()

isc::db::PgSqlTransaction::PgSqlTransaction ( PgSqlConnection conn)

Constructor.

Starts transaction by executing the SQL statement: "START TRANSACTION"

Parameters
connPostgreSQL connection to use for the transaction. This connection will be later used to commit or rollback changes.
Exceptions
DbOperationErrorif statement execution fails

Definition at line 114 of file pgsql_connection.cc.

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

+ Here is the call graph for this function:

◆ ~PgSqlTransaction()

isc::db::PgSqlTransaction::~PgSqlTransaction ( )

Destructor.

If the transaction has not been committed, it is rolled back by executing the SQL statement: "ROLLBACK"

Exceptions
DbOperationErrorif statement execution fails

Definition at line 119 of file pgsql_connection.cc.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ commit()

void isc::db::PgSqlTransaction::commit ( )

Commits transaction.

Commits all changes made during the transaction by executing the SQL statement: "COMMIT"

Exceptions
DbOperationErrorif statement execution fails

Definition at line 127 of file pgsql_connection.cc.

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

Referenced by isc::dhcp::PgSqlHostDataSource::add(), and isc::dhcp::PgSqlHostDataSource::update().

+ Here is the call graph for this function:

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