4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
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
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published
11
* by the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
6
* This file is part of sqlite3cc (hereafter referred to as "this program").
7
* See http://ed.am/dev/sqlite3cc for more information.
9
* This program is free software: you can redistribute it and/or modify it under
10
* the terms of the GNU Lesser General Public License as published by the Free
11
* Software Foundation, either version 3 of the License, or (at your option) any
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19
19
* You should have received a copy of the GNU Lesser General Public License
20
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef TRANSACTION_HPP_
24
#define TRANSACTION_HPP_
23
#ifndef SQLITE3CC_TRANSACTION_H_
24
#define SQLITE3CC_TRANSACTION_H_
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.
55
* @param connection a connection
57
explicit basic_transaction(
58
connection &connection );
60
//__________________________________________________________________________
65
* Begin the transaction
70
* Commit the transaction
72
virtual void commit();
75
* Rollback the transaction
77
virtual void rollback();
79
//__________________________________________________________________________
83
/** reset any in-progress statements */
84
void reset_active_queries();
86
/** the connection on which to act */
87
connection &_connection;
94
////////////////////////////////////////////////////////////////////////////////
98
* A deferred transaction.
100
typedef detail::basic_transaction deferred_transaction;
103
////////////////////////////////////////////////////////////////////////////////
107
* An immediate transaction.
109
class immediate_transaction
111
public detail::basic_transaction
113
//______________________________________________________________________________
118
* Constructor that provides a connection upon which to act.
120
* @param connection a connection
122
explicit immediate_transaction(
123
connection &connection );
125
//______________________________________________________________________________
130
* Begin the transaction.
132
virtual void begin();
137
////////////////////////////////////////////////////////////////////////////////
141
* An exclusive transaction.
143
class exclusive_transaction
145
public detail::basic_transaction
147
//______________________________________________________________________________
152
* Constructor that provides a connection upon which to act.
154
* @param connection a connection
156
explicit exclusive_transaction(
157
connection &connection );
159
//______________________________________________________________________________
164
* Begin the transaction
166
virtual void begin();
171
////////////////////////////////////////////////////////////////////////////////
175
* A recursive transaction, allowing transactions to be nested.
177
class recursive_transaction
179
public detail::basic_transaction
181
//______________________________________________________________________________
186
* Constructor that provides a connection upon which to act.
188
* @param connection a connection
190
explicit recursive_transaction(
191
connection &connection );
193
//______________________________________________________________________________
198
* Begin the transaction.
200
virtual void begin();
203
* Commit the transaction.
205
virtual void commit();
208
* Rollback the transaction.
210
virtual void rollback();
212
//______________________________________________________________________________
216
/* this transaction's savepoint name */
217
std::string _sp_name;
222
////////////////////////////////////////////////////////////////////////////////
226
* A scope guard (sentinel) for use with one of the transaction classes to
227
* provide RAII-style transactions. It defaults to using deferred transactions.
229
template< class T = deferred_transaction >
230
class transaction_guard
39
232
private boost::noncopyable
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 = "" );
239
* Constructor that provides a connection upon which to act.
241
* @param connection a connection
243
explicit transaction_guard(
244
connection &connection )
246
_transaction( connection ),
249
_transaction.begin();
256
_transaction.rollback();
70
259
//______________________________________________________________________________
71
260
// public interface
74
* Commit the transaction
76
virtual void commit();
79
* Rollback the transaction
264
* Begin the transaction. Note that this is done automatically in the
270
_transaction.begin();
276
* Commit the transaction.
281
_transaction.commit();
287
* Rollback the transaction. Note that this is done automatically in the
288
* destructor if the transaction hasn't otherwise been completed.
293
_transaction.rollback();
83
298
//______________________________________________________________________________
90
/** the SQL used to rollback the transaction, or empty to use default */
91
std::string _rollback_sql;
96
////////////////////////////////////////////////////////////////////////////////
99
class exclusive_transaction
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_ */
302
/** the transaction */
305
/** have we released the transaction yet? */
311
} // namespace sqlite
314
#endif /* SQLITE3CC_TRANSACTION_H_ */