4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
6
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.
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.
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/>.
39
* A basic (default, deferred) transaction.
41
class basic_transaction
43
private boost::noncopyable
45
//______________________________________________________________________________
50
* Constructor that provides a database upon which to act
51
* @param database a database
53
explicit basic_transaction(
56
//______________________________________________________________________________
61
* Begin the transaction
66
* Commit the transaction
68
virtual void commit();
71
* Rollback the transaction
73
virtual void rollback();
75
//______________________________________________________________________________
79
/* the database on which to act */
85
////////////////////////////////////////////////////////////////////////////////
89
* An exclusive transaction
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.
91
109
class immediate_transaction
93
public basic_transaction
111
public detail::basic_transaction
95
113
//______________________________________________________________________________
100
* Constructor that provides a database upon which to act
101
* @param database a database
118
* Constructor that provides a connection upon which to act.
120
* @param connection a connection
103
122
explicit immediate_transaction(
104
database &database );
123
connection &connection );
106
125
//______________________________________________________________________________
107
126
// public interface
111
* Begin the transaction
130
* Begin the transaction.
113
132
virtual void begin();
122
* An exclusive transaction
141
* An exclusive transaction.
124
143
class exclusive_transaction
126
public basic_transaction
145
public detail::basic_transaction
128
147
//______________________________________________________________________________
133
* Constructor that provides a database upon which to act
134
* @param database a database
152
* Constructor that provides a connection upon which to act.
154
* @param connection a connection
136
156
explicit exclusive_transaction(
137
database &database );
157
connection &connection );
139
159
//______________________________________________________________________________
140
160
// public interface
157
177
class recursive_transaction
159
public basic_transaction
179
public detail::basic_transaction
161
181
//______________________________________________________________________________
166
* Constructor that provides a database upon which to act
167
* @param database a database
186
* Constructor that provides a connection upon which to act.
188
* @param connection a connection
169
190
explicit recursive_transaction(
170
database &database );
191
connection &connection );
172
193
//______________________________________________________________________________
173
194
// public interface
177
* Begin the transaction
198
* Begin the transaction.
179
200
virtual void begin();
182
* Commit the transaction
203
* Commit the transaction.
184
205
virtual void commit();
187
* Rollback the transaction
208
* Rollback the transaction.
189
210
virtual void rollback();
205
* A scope guard, or sentinel for use with one of the transaction classes.
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.
207
template< class T = basic_transaction >
229
template< class T = deferred_transaction >
208
230
class transaction_guard
210
232
private boost::noncopyable
217
* Constructor that provides a database upon which to act
218
* @param database a database
239
* Constructor that provides a connection upon which to act.
241
* @param connection a connection
220
243
explicit transaction_guard(
244
connection &connection )
223
_transaction( database ),
246
_transaction( connection ),
226
249
_transaction.begin();
229
253
~transaction_guard()
233
_transaction.rollback();
256
_transaction.rollback();
240
259
//______________________________________________________________________________
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();
255
298
//______________________________________________________________________________
256
299
// implementation
259
/* the transaction */
302
/** the transaction */
262
/* have we released the transaction yet? */
305
/** have we released the transaction yet? */