4
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
* This file is part of sqlite3cc (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
6
* This file is part of sqlitepp (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlitepp for more information.
9
9
* This program is free software: you can redistribute it and/or modify
10
10
* it under the terms of the GNU Lesser General Public License as published
50
46
* Constructor that provides a database upon which to act
51
47
* @param database a database
53
explicit basic_transaction(
54
50
database &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 = "" );
56
70
//______________________________________________________________________________
57
71
// public interface
61
* Begin the transaction
66
74
* Commit the transaction
71
79
* Rollback the transaction
73
virtual void rollback();
75
83
//______________________________________________________________________________
79
/** close any in-progress statements */
80
void invalidate_queries();
82
/** the database on which to act */
83
88
database &_database;
88
////////////////////////////////////////////////////////////////////////////////
92
* An exclusive transaction
94
class immediate_transaction
96
public basic_transaction
98
//______________________________________________________________________________
103
* Constructor that provides a database upon which to act
104
* @param database a database
106
explicit immediate_transaction(
107
database &database );
109
//______________________________________________________________________________
114
* Begin the transaction
116
virtual void begin();
121
////////////////////////////////////////////////////////////////////////////////
125
* An exclusive transaction
90
/** the SQL used to rollback the transaction, or empty to use default */
91
std::string _rollback_sql;
96
////////////////////////////////////////////////////////////////////////////////
127
99
class exclusive_transaction
129
public basic_transaction
131
//______________________________________________________________________________
136
* Constructor that provides a database upon which to act
137
* @param database a database
139
explicit exclusive_transaction(
140
database &database );
142
//______________________________________________________________________________
147
* Begin the transaction
149
virtual void begin();
154
////////////////////////////////////////////////////////////////////////////////
158
* A recursive transaction, allowing transactions to be nested.
160
class recursive_transaction
162
public basic_transaction
164
//______________________________________________________________________________
169
* Constructor that provides a database upon which to act
170
* @param database a database
172
explicit recursive_transaction(
173
database &database );
175
//______________________________________________________________________________
180
* Begin the transaction
182
virtual void begin();
185
* Commit the transaction
187
virtual void commit();
190
* Rollback the transaction
192
virtual void rollback();
194
//______________________________________________________________________________
198
/* this transaction's savepoint name */
199
std::string _sp_name;
204
////////////////////////////////////////////////////////////////////////////////
208
* A scope guard, or sentinel for use with one of the transaction classes.
210
template< class T = basic_transaction >
211
class transaction_guard
213
private boost::noncopyable
215
//______________________________________________________________________________
220
* Constructor that provides a database upon which to act
221
* @param database a database
223
explicit transaction_guard(
226
_transaction( database ),
229
_transaction.begin();
236
_transaction.rollback();
243
//______________________________________________________________________________
248
* Commit the transaction
253
_transaction.commit();
258
//______________________________________________________________________________
262
/** the transaction */
265
/** have we released the transaction yet? */
271
} // namespace sqlite
274
#endif /* SQLITE3CC_TRANSACTION_H_ */
103
//______________________________________________________________________________
108
* Constructor that provides a database upon which to act
109
* @param database a database
111
exclusive_transaction(
112
database &database );
120
#endif /* TRANSACTION_HPP_ */