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
/* the database on which to act */
80
88
database &_database;
85
////////////////////////////////////////////////////////////////////////////////
89
* An exclusive transaction
91
class immediate_transaction
93
public basic_transaction
95
//______________________________________________________________________________
100
* Constructor that provides a database upon which to act
101
* @param database a database
103
explicit immediate_transaction(
104
database &database );
106
//______________________________________________________________________________
111
* Begin the transaction
113
virtual void begin();
118
////////////////////////////////////////////////////////////////////////////////
122
* An exclusive transaction
90
/** the SQL used to rollback the transaction, or empty to use default */
91
std::string _rollback_sql;
96
////////////////////////////////////////////////////////////////////////////////
124
99
class exclusive_transaction
126
public basic_transaction
128
//______________________________________________________________________________
133
* Constructor that provides a database upon which to act
134
* @param database a database
136
explicit exclusive_transaction(
137
database &database );
139
//______________________________________________________________________________
144
* Begin the transaction
146
virtual void begin();
151
////////////////////////////////////////////////////////////////////////////////
155
* A recursive transaction, allowing transactions to be nested.
157
class recursive_transaction
159
public basic_transaction
161
//______________________________________________________________________________
166
* Constructor that provides a database upon which to act
167
* @param database a database
169
explicit recursive_transaction(
170
database &database );
172
//______________________________________________________________________________
177
* Begin the transaction
179
virtual void begin();
182
* Commit the transaction
184
virtual void commit();
187
* Rollback the transaction
189
virtual void rollback();
191
//______________________________________________________________________________
195
/* this transaction's savepoint name */
196
std::string _sp_name;
201
////////////////////////////////////////////////////////////////////////////////
205
* A scope guard, or sentinel for use with one of the transaction classes.
207
template< class T = basic_transaction >
208
class transaction_guard
210
private boost::noncopyable
212
//______________________________________________________________________________
217
* Constructor that provides a database upon which to act
218
* @param database a database
220
explicit transaction_guard(
223
_transaction( database ),
226
_transaction.begin();
233
_transaction.rollback();
240
//______________________________________________________________________________
245
* Commit the transaction
250
_transaction.commit();
255
//______________________________________________________________________________
259
/* the transaction */
262
/* have we released the transaction yet? */
268
} // namespace sqlite
271
#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_ */