4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
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
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.
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/>.
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
38
class basic_transaction
111
public detail::basic_transaction
40
private boost::noncopyable
113
42
//______________________________________________________________________________
118
* Constructor that provides a connection upon which to act.
120
* @param connection a connection
47
* Constructor that provides a database upon which to act
48
* @param database a database
122
explicit immediate_transaction(
123
connection &connection );
50
explicit basic_transaction(
125
53
//______________________________________________________________________________
126
54
// public interface
130
* Begin the transaction.
58
* Begin the transaction
132
60
virtual void begin();
63
* Commit the transaction
65
virtual void commit();
68
* Rollback the transaction
70
virtual void rollback();
72
//______________________________________________________________________________
76
/* the database on which to act */
137
82
////////////////////////////////////////////////////////////////////////////////
141
* An exclusive transaction.
143
85
class exclusive_transaction
145
public detail::basic_transaction
87
public basic_transaction
147
89
//______________________________________________________________________________
152
* Constructor that provides a connection upon which to act.
154
* @param connection a connection
94
* Constructor that provides a database upon which to act
95
* @param database a database
156
97
explicit exclusive_transaction(
157
connection &connection );
159
100
//______________________________________________________________________________
160
101
// public interface
171
112
////////////////////////////////////////////////////////////////////////////////
175
* A recursive transaction, allowing transactions to be nested.
177
115
class recursive_transaction
179
public detail::basic_transaction
117
public basic_transaction
181
119
//______________________________________________________________________________
186
* Constructor that provides a connection upon which to act.
188
* @param connection a connection
124
* Constructor that provides a database upon which to act
125
* @param database a database
190
127
explicit recursive_transaction(
191
connection &connection );
128
database &database );
193
130
//______________________________________________________________________________
194
131
// public interface
198
* Begin the transaction.
135
* Begin the transaction
200
137
virtual void begin();
203
* Commit the transaction.
140
* Commit the transaction
205
142
virtual void commit();
208
* Rollback the transaction.
145
* Rollback the transaction
210
147
virtual void rollback();
222
159
////////////////////////////////////////////////////////////////////////////////
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 >
162
template< class T = basic_transaction >
230
163
class transaction_guard
232
165
private boost::noncopyable
239
* Constructor that provides a connection upon which to act.
241
* @param connection a connection
172
* Constructor that provides a database upon which to act
173
* @param database a database
243
175
explicit transaction_guard(
244
connection &connection )
246
_transaction( connection ),
178
_transaction( database ),
249
181
_transaction.begin();
253
184
~transaction_guard()
256
_transaction.rollback();
188
_transaction.rollback();
259
195
//______________________________________________________________________________