ROSE  0.11.54.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SqlDatabase::Transaction Class Reference

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 278 of file SqlDatabase.h.

#include <SqlDatabase.h>

Inheritance diagram for SqlDatabase::Transaction:
Inheritance graph
[legend]
Collaboration diagram for SqlDatabase::Transaction:
Collaboration graph
[legend]

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

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.


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