Public Member Functions

SimpleDB::ScopedTransaction Class Reference

ScopedTransaction class Create a scoped transaction to make a block of code into a transaction If this object destructs before the commit function is called, the transaction will be rolled back. More...

#include <ScopedTransaction.h>

List of all members.

Public Member Functions

 ScopedTransaction (Database &database)
 Begin a transaction on the given database connection.
virtual void commit ()
 Commit the transaction.
virtual void rollback ()
 Rollback the transaction.
virtual ~ScopedTransaction ()
 Virtual destructor This will rollback the transaction if the commit function was not called on the transaction.

Detailed Description

ScopedTransaction class Create a scoped transaction to make a block of code into a transaction If this object destructs before the commit function is called, the transaction will be rolled back.

Otherwise, the transaction will be committed. This makes it easy to create exception safe code. You can nest ScopedTransaction as a count is kept on each database connection so that a transations are only committed or rolled back by the outermost transaction object.

If a nested transaction is rolled back, no further queries can take place until all of the nesting transactions have gone out of scope.

Please note that "applications should not use Transact-SQL transaction statements such as BEGIN TRANSACTION, COMMIT TRANSACTION, or ROLLBACK TRANSACTION because this can cause indeterminate behavior in the driver" http://msdn2.microsoft.com/en-us/library/ms131281(SQL.90).aspx

I.e., use this object ;)

Examples:

transactions.cpp.


Constructor & Destructor Documentation

SimpleDB::ScopedTransaction::ScopedTransaction ( Database database  ) 

Begin a transaction on the given database connection.

Parameters:
database The database connection

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

Documentation pages generated by doxygen.
SourceForge.net Logo