Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pqxxobject::transaction Class Reference

Database transaction convenience wrapper. More...

#include <transaction.h>

List of all members.

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


Detailed Description

Database transaction convenience wrapper.

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.


Member Enumeration Documentation

enum pqxxobject::transaction::state
 

Enumeration values:
STATE_NONE 
STATE_ABORTED 
STATE_COMMITTED 
STATE_EXECUTING 

Definition at line 49 of file transaction.h.


Constructor & Destructor Documentation

transaction::transaction pqxx::connection &  connection,
pqxx::transaction<> *&  transaction
 

The constructor.

Parameters:
connection a reference to a PostgreSQL database connection object.
transaction a pointer to a PostgreSQL transaction object. This must have been previously created from connection. If set to NULL, transaction will run in auto-commit mode, and will create a new transaction for each database operation.

Definition at line 29 of file transaction.cc.

References m_autocommit, and m_transaction.

transaction::~transaction  )  [virtual]
 

The destructor.

Definition at line 42 of file transaction.cc.


Member Function Documentation

void transaction::abort  ) 
 

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.

Referenced by end(), and perform().

void transaction::begin const std::string &  name  ) 
 

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.

Parameters:
name the name to give the transaction. This may be zero length, but will be shown on error messages relating to the transaction.

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().

void transaction::commit  ) 
 

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().

void transaction::end  ) 
 

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().

pqxx::result transaction::exec const std::string &  query  ) 
 

Execute a query.

This method should be called to run an SQL statement on the database server.

Parameters:
query the SQL statement to run.
Returns:
a pointer to the result set. This is allocated with new and must be deleted when finished with.

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().

pqxx::result::size_type transaction::exec_noresult const std::string &  query  ) 
 

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.

Parameters:
query the SQL statement to run.
Returns:
the number of rows the query affected.

Definition at line 117 of file transaction.cc.

References exec().

Referenced by perform().

pqxx::result::size_type transaction::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.

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.

Parameters:
query the SQL statement to run.
min_rows the minimum number of rows to be altered. If the number of rows is greater than or equal to this number, the transaction is committed or else it is aborted. If set to 0, the operation will always be committed.
max_rows the maximum number of rows to be altered. If the number of rows is less that or equal to this number, the transaction is committed or else it is aborted. If set to 0, the operation will always be committed.
Returns:
the number of rows the query affected.

Definition at line 131 of file transaction.cc.

References abort(), begin(), commit(), end(), and exec_noresult().

SigC::Signal0< void > & transaction::signal_abort  ) 
 

Definition at line 53 of file transaction.cc.

References m_signal_abort.

SigC::Signal0< void > & transaction::signal_commit  ) 
 

Definition at line 47 of file transaction.cc.

References m_signal_commit.


Member Data Documentation

bool pqxxobject::transaction::m_autocommit
 

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().

pqxx::connection& pqxxobject::transaction::m_connection
 

A reference to a PostgreSQL database connection object.

Definition at line 172 of file transaction.h.

Referenced by begin().

SigC::Signal0<void> pqxxobject::transaction::m_signal_abort
 

Definition at line 179 of file transaction.h.

Referenced by abort(), and signal_abort().

SigC::Signal0<void> pqxxobject::transaction::m_signal_commit
 

Definition at line 178 of file transaction.h.

Referenced by commit(), and signal_commit().

state pqxxobject::transaction::m_state
 

Definition at line 181 of file transaction.h.

Referenced by abort(), begin(), commit(), and end().

pqxx::transaction*& pqxxobject::transaction::m_transaction
 

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().


The documentation for this class was generated from the following files:
Generated on Sat Jan 17 20:58:43 2004 for pqxx-object API Reference by doxygen 1.3.4