ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlDatabase::Transaction Class Reference

Unit of work within a database. More...

#include <SqlDatabase.h>

Inheritance diagram for SqlDatabase::Transaction:
Collaboration diagram for SqlDatabase::Transaction:

Public Member Functions

void rollback ()
 Cancel a transaction. More...
 
void commit ()
 Complete a transaction. More...
 
bool is_terminated () const
 Returns termination status. More...
 
StatementPtr statement (const std::string &sql)
 Create a new statement. More...
 
void execute (const std::string &sql)
 Execute one or more statements. More...
 
void bulk_load (const std::string &tablename, std::istream &)
 Bulk load data into table. More...
 
Driver driver () const
 Returns the low-level driver name for this transaction. More...
 
ConnectionPtr connection () const
 Returns the connection for this transaction. More...
 
void print (std::ostream &) const
 Print some basic info about this transaction. More...
 
 ~Transaction ()
 
void set_debug (FILE *f)
 Debugging property. More...
 
FILE * get_debug () const
 Debugging property. More...
 

Static Public Member Functions

static TransactionPtr create (const ConnectionPtr &conn)
 Create a new transaction. More...
 

Protected Member Functions

 Transaction (const ConnectionPtr &conn, size_t drv_conn)
 

Private Member Functions

void init (const ConnectionPtr &conn, size_t drv_conn)
 
void finish ()
 

Private Attributes

TransactionImpl * impl
 

Friends

class ConnectionImpl
 
class Statement
 
class StatementImpl
 

Detailed Description

Unit of work within a database.

A transaction comprises a unit of work performed against a database and treated in a coherent and reliable way independent of other transactions. A database connection may have multiple transactions and all statements are executed within a transaction. A transaction is obtained (and started) via Connection::transaction(). A transaction can be canceled with its rollback() method or by deletion; it can be completed by calling its commit() method. A transaction that has been canceled or completed can no longer be used.

Definition at line 257 of file SqlDatabase.h.

Constructor & Destructor Documentation

SqlDatabase::Transaction::~Transaction ( )
inline

Definition at line 312 of file SqlDatabase.h.

SqlDatabase::Transaction::Transaction ( const ConnectionPtr conn,
size_t  drv_conn 
)
inlineexplicitprotected

Definition at line 315 of file SqlDatabase.h.

References Dbg::init().

Member Function Documentation

static TransactionPtr SqlDatabase::Transaction::create ( const ConnectionPtr conn)
static

Create a new transaction.

Transactions can be created either by this class method or by calling Connection::transaction(). The transaction will exist until there are no references (user or statements). Transactions must be explicitly completed via commit(), or its statements will have no effect on the database.

void SqlDatabase::Transaction::rollback ( )

Cancel a transaction.

The statements that executed within this transaction are rolled back so that they do not have any effect on the database. Once this transaction is rolled back it enters a terminated state and cannot be used; any method call (other than is_terminated()) will result in an exception.

void SqlDatabase::Transaction::commit ( )

Complete a transaction.

The statements that executed within this transaction are completed so that their effects are visible in the database. Once this transaction is committed it enters a terminated state and cannot be used; any method call (other than is_terminated()) will result in an exception.

bool SqlDatabase::Transaction::is_terminated ( ) const

Returns termination status.

A transaction is terminated if it has been canceled or completed via rollback() or commit(), respectively.

StatementPtr SqlDatabase::Transaction::statement ( const std::string &  sql)

Create a new statement.

void SqlDatabase::Transaction::execute ( const std::string &  sql)

Execute one or more statements.

The provided SQL source code is parsed into individual statements and executed one statement at a time until all are processed or statement fails causing an exception to be thrown. All results are discarded. The transaction is not automatically committed.

void SqlDatabase::Transaction::bulk_load ( const std::string &  tablename,
std::istream &   
)

Bulk load data into table.

The specified input stream contains comma-separated values which are inserted in bulk into the specified table. The number of fields in each row of the input stream must match the number of columns in the table. Some drivers require that a bulk load is the only operation performed in a transaction.

Driver SqlDatabase::Transaction::driver ( ) const

Returns the low-level driver name for this transaction.

ConnectionPtr SqlDatabase::Transaction::connection ( ) const

Returns the connection for this transaction.

void SqlDatabase::Transaction::set_debug ( FILE *  f)

Debugging property.

If non-null, then debugging information is sent to that file. Transactions inherit the debugging property of their connection (which is overridden by this method), and statements inherit the debugging property of their transaction.

FILE* SqlDatabase::Transaction::get_debug ( ) const

Debugging property.

If non-null, then debugging information is sent to that file. Transactions inherit the debugging property of their connection (which is overridden by this method), and statements inherit the debugging property of their transaction.

void SqlDatabase::Transaction::print ( std::ostream &  ) const

Print some basic info about this transaction.

void SqlDatabase::Transaction::init ( const ConnectionPtr conn,
size_t  drv_conn 
)
private
void SqlDatabase::Transaction::finish ( )
private

Friends And Related Function Documentation

friend class ConnectionImpl
friend

Definition at line 258 of file SqlDatabase.h.

friend class Statement
friend

Definition at line 259 of file SqlDatabase.h.

friend class StatementImpl
friend

Definition at line 260 of file SqlDatabase.h.

Member Data Documentation

TransactionImpl* SqlDatabase::Transaction::impl
private

Definition at line 322 of file SqlDatabase.h.


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