#include <transaction.h>
Public Types | |
enum | state { STATE_NONE, STATE_ABORTED, STATE_COMMITTED, STATE_EXECUTING } |
Public Member Functions | |
transaction (pqxx::connection &connection, pqxx::transaction<> *&transaction) | |
The constructor. | |
virtual | ~transaction () |
The destructor. | |
void | begin (const std::string &name) |
Begin a new transaction. | |
void | end () |
End a transaction. | |
pqxx::result | exec (const std::string &query) |
Execute a query. | |
pqxx::result::size_type | exec_noresult (const std::string &query) |
Execute a query without seeing the result set. | |
pqxx::result::size_type | perform (const std::string &query, pqxx::result::size_type min_rows, pqxx::result::size_type max_rows) |
Execute a query and automatically commit or abort the changes. | |
void | commit () |
Commit a transaction to the database. | |
void | abort () |
Abort a transaction. | |
SigC::Signal0< void > & | signal_commit () |
SigC::Signal0< void > & | signal_abort () |
Public Attributes | |
pqxx::connection & | m_connection |
A reference to a PostgreSQL database connection object. | |
pqxx::transaction *& | m_transaction |
A reference to a pointer to a PostgreSQL transaction object. | |
bool | m_autocommit |
Set to true if auto-commit mode is in use, or else set to false. | |
SigC::Signal0< void > | m_signal_commit |
SigC::Signal0< void > | m_signal_abort |
state | m_state |
This class provides methods to simplify database access for classes which perform any sort of database interaction. Methods are provided to begin and end transactions, and commit and abort transactions.
The class provides two modes of operation: auto-commit mode, where transactions are created and destroyed on-the-fly, and non-auto-commit mode, where the user supplies a transaction at construction time, and this is persistent through the lifetime of the object.
Definition at line 46 of file transaction.h.
|
Definition at line 49 of file transaction.h. |
|
The constructor.
Definition at line 29 of file transaction.cc. References m_autocommit, and m_transaction. |
|
The destructor.
Definition at line 42 of file transaction.cc. |
|
Abort a transaction. This method should be called after an error, to revert any changes. The changes will be rolled back to their state at the start of the transaction as a single operation. After calling this method, the transaction may no longer be used. On abort, the signal_abort signal is emitted. This method has no effect when not running in auto-commit mode. Definition at line 186 of file transaction.cc. References end(), m_autocommit, m_signal_abort, m_state, m_transaction, and STATE_ABORTED. |
|
Begin a new transaction. This method should be called at the start of any database operation. When running in auto-commit mode, a new pqxx::Transaction object is created. This method has no effect when not running in auto-commit mode.
Definition at line 59 of file transaction.cc. References end(), m_autocommit, m_connection, m_state, m_transaction, and STATE_EXECUTING. Referenced by pqxxobject::table< Row >::find_many(), pqxxobject::table< Row >::find_one(), and perform(). |
|
Commit a transaction to the database. This method should be called after the successful completion of one, or a series of, successful database operations. The changes will be committed to the database as one single operation. After calling this method, the transaction may no longer be used. On commit, the signal_commit signal is emitted. This method has no effect when not running in auto-commit mode. Definition at line 165 of file transaction.cc. References end(), m_autocommit, m_signal_commit, m_state, m_transaction, and STATE_COMMITTED. Referenced by perform(). |
|
End a transaction. This method should be called at the end of any database operation. When running in auto-commit mode, the pqxx::Transaction object is deleted. This method has no effect when not running in auto-commit mode. Definition at line 81 of file transaction.cc. References abort(), m_autocommit, m_state, m_transaction, STATE_EXECUTING, and STATE_NONE. Referenced by abort(), begin(), commit(), pqxxobject::table< Row >::find_many(), pqxxobject::table< Row >::find_one(), and perform(). |
|
Execute a query. This method should be called to run an SQL statement on the database server.
Definition at line 104 of file transaction.cc. References m_transaction. Referenced by exec_noresult(), pqxxobject::table< Row >::find_many(), and pqxxobject::table< Row >::find_one(). |
|
Execute a query without seeing the result set. This method should be called to run an SQL statement on the database server. Unlike exec_query(), this method frees the result set automatically. Use exec_query if access to the result set is required.
Definition at line 117 of file transaction.cc. References exec(). Referenced by perform(). |
|
Execute a query and automatically commit or abort the changes. This method should be called to run an SQL statement on the database server. Unlike exec_query(), this method frees the result set automatically. Use exec_query if access to the result set is required. The transaction will be committed or aborted if running in auto-commit mode.
Definition at line 131 of file transaction.cc. References abort(), begin(), commit(), end(), and exec_noresult(). |
|
Definition at line 53 of file transaction.cc. References m_signal_abort. |
|
Definition at line 47 of file transaction.cc. References m_signal_commit. |
|
Set to true if auto-commit mode is in use, or else set to false.
Definition at line 176 of file transaction.h. Referenced by abort(), begin(), commit(), end(), and transaction(). |
|
A reference to a PostgreSQL database connection object.
Definition at line 172 of file transaction.h. Referenced by begin(). |
|
Definition at line 179 of file transaction.h. Referenced by abort(), and signal_abort(). |
|
Definition at line 178 of file transaction.h. Referenced by commit(), and signal_commit(). |
|
Definition at line 181 of file transaction.h. |
|
A reference to a pointer to a PostgreSQL transaction object.
Definition at line 174 of file transaction.h. Referenced by abort(), begin(), commit(), end(), exec(), and transaction(). |