20
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef SQLITE3CC_TRANSACTION_H_
24
#define SQLITE3CC_TRANSACTION_H_
23
#ifndef TRANSACTION_HPP_
24
#define TRANSACTION_HPP_
27
27
#include <boost/utility.hpp>
42
* A basic (default, deferred) transaction.
44
class basic_transaction
46
private boost::noncopyable
48
//__________________________________________________________________________
53
* Constructor that provides a connection upon which to act
54
* @param connection a connection
56
explicit basic_transaction(
57
connection &connection );
59
//__________________________________________________________________________
64
* Begin the transaction
69
* Commit the transaction
71
virtual void commit();
74
* Rollback the transaction
76
virtual void rollback();
78
//__________________________________________________________________________
82
/** reset any in-progress statements */
83
void reset_active_queries();
85
/** the connection on which to act */
86
connection &_connection;
93
////////////////////////////////////////////////////////////////////////////////
97
* A deferred transaction
99
typedef detail::basic_transaction deferred_transaction;
102
////////////////////////////////////////////////////////////////////////////////
106
* An immediate transaction
108
class immediate_transaction
110
public detail::basic_transaction
112
//______________________________________________________________________________
117
* Constructor that provides a connection upon which to act
118
* @param connection a connection
120
explicit immediate_transaction(
121
connection &connection );
123
//______________________________________________________________________________
128
* Begin the transaction
130
virtual void begin();
135
////////////////////////////////////////////////////////////////////////////////
139
* An exclusive transaction
141
class exclusive_transaction
143
public detail::basic_transaction
145
//______________________________________________________________________________
150
* Constructor that provides a connection upon which to act
151
* @param connection a connection
153
explicit exclusive_transaction(
154
connection &connection );
156
//______________________________________________________________________________
161
* Begin the transaction
163
virtual void begin();
168
////////////////////////////////////////////////////////////////////////////////
172
* A recursive transaction, allowing transactions to be nested.
174
class recursive_transaction
176
public detail::basic_transaction
178
//______________________________________________________________________________
183
* Constructor that provides a connection upon which to act
184
* @param connection a connection
186
explicit recursive_transaction(
187
connection &connection );
189
//______________________________________________________________________________
194
* Begin the transaction
196
virtual void begin();
39
private boost::noncopyable
41
//______________________________________________________________________________
46
* Constructor that provides a database upon which to act
47
* @param database a database
52
virtual ~transaction() throw( );
57
* Constructor that provides a way for deriving classes to override the SQL
58
* executed in beginning and rolling-back a transaction during construction
60
* @param database a database
61
* @param begin_sql the SQL statement used to begin the transaction
62
* @param rollback_sql the SQL statement used to rollback the transaction,
63
* or an empty string if the default is to be used.
67
const std::string &begin_sql,
68
const std::string &rollback_sql = "" );
70
//______________________________________________________________________________
199
74
* Commit the transaction
218
96
////////////////////////////////////////////////////////////////////////////////
222
* A scope guard (sentinel) for use with one of the transaction
223
* classes to provide RAII-style transactions. It defaults to using
224
* deferred transactions.
226
template< class T = deferred_transaction >
227
class transaction_guard
99
class exclusive_transaction
229
private boost::noncopyable
231
103
//______________________________________________________________________________
236
* Constructor that provides a connection upon which to act
237
* @param connection a connection
239
explicit transaction_guard(
240
connection &connection )
242
_transaction( connection ),
245
_transaction.begin();
251
_transaction.rollback();
254
//______________________________________________________________________________
259
* Commit the transaction
264
_transaction.commit();
270
* Rollback the transaction early
275
_transaction.rollback();
280
//______________________________________________________________________________
284
/** the transaction */
287
/** have we released the transaction yet? */
108
* Constructor that provides a database upon which to act
109
* @param database a database
111
exclusive_transaction(
112
database &database );
293
} // namespace sqlite
296
#endif /* SQLITE3CC_TRANSACTION_H_ */
120
#endif /* TRANSACTION_HPP_ */