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
20
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef SQLITE3CC_TRANSACTION_H_
24
#define SQLITE3CC_TRANSACTION_H_
23
#ifndef TRANSACTION_HPP_
24
#define TRANSACTION_HPP_
27
27
#include <boost/utility.hpp>
46
46
* Constructor that provides a database upon which to act
47
47
* @param database a database
49
explicit basic_transaction(
50
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 = "" );
52
70
//______________________________________________________________________________
53
71
// public interface
57
* Begin the transaction
62
74
* Commit the transaction
67
79
* Rollback the transaction
69
virtual void rollback();
71
83
//______________________________________________________________________________
75
/* the database on which to act */
76
88
database &_database;
90
/** the SQL used to rollback the transaction, or empty to use default */
91
std::string _rollback_sql;
84
99
class exclusive_transaction
86
public basic_transaction
88
//______________________________________________________________________________
93
* Constructor that provides a database upon which to act
94
* @param database a database
96
explicit exclusive_transaction(
99
//______________________________________________________________________________
104
* Begin the transaction
106
virtual void begin();
111
////////////////////////////////////////////////////////////////////////////////
114
class recursive_transaction
116
public basic_transaction
118
//______________________________________________________________________________
123
* Constructor that provides a database upon which to act
124
* @param database a database
126
explicit recursive_transaction(
127
database &database );
129
//______________________________________________________________________________
134
* Begin the transaction
136
virtual void begin();
139
* Commit the transaction
141
virtual void commit();
144
* Rollback the transaction
146
virtual void rollback();
148
//______________________________________________________________________________
152
/* this transaction's savepoint name */
153
std::string _sp_name;
158
////////////////////////////////////////////////////////////////////////////////
161
template< class T = basic_transaction >
162
class transaction_guard
164
private boost::noncopyable
166
//______________________________________________________________________________
171
* Constructor that provides a database upon which to act
172
* @param database a database
174
explicit transaction_guard(
177
_transaction( database ),
180
_transaction.begin();
186
_transaction.rollback();
189
//______________________________________________________________________________
194
* Commit the transaction
199
_transaction.commit();
204
//______________________________________________________________________________
208
/* the transaction */
211
/* have we released the transaction yet? */
217
} // namespace sqlite
220
#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_ */