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>
47
46
* Constructor that provides a database upon which to act
48
47
* @param database a database
50
explicit basic_transaction(
51
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 = "" );
53
70
//______________________________________________________________________________
54
71
// public interface
58
* Begin the transaction
63
74
* Commit the transaction
68
79
* Rollback the transaction
70
virtual void rollback();
72
83
//______________________________________________________________________________
76
/* the database on which to act */
77
88
database &_database;
90
/** the SQL used to rollback the transaction, or empty to use default */
91
std::string _rollback_sql;
85
99
class exclusive_transaction
87
public basic_transaction
89
//______________________________________________________________________________
94
* Constructor that provides a database upon which to act
95
* @param database a database
97
explicit exclusive_transaction(
100
//______________________________________________________________________________
105
* Begin the transaction
107
virtual void begin();
112
////////////////////////////////////////////////////////////////////////////////
115
class recursive_transaction
117
public basic_transaction
119
//______________________________________________________________________________
124
* Constructor that provides a database upon which to act
125
* @param database a database
127
explicit recursive_transaction(
128
database &database );
130
//______________________________________________________________________________
135
* Begin the transaction
137
virtual void begin();
140
* Commit the transaction
142
virtual void commit();
145
* Rollback the transaction
147
virtual void rollback();
149
//______________________________________________________________________________
153
/* this transaction's savepoint name */
154
std::string _sp_name;
159
////////////////////////////////////////////////////////////////////////////////
162
template< class T = basic_transaction >
163
class transaction_guard
165
private boost::noncopyable
167
//______________________________________________________________________________
172
* Constructor that provides a database upon which to act
173
* @param database a database
175
explicit transaction_guard(
178
_transaction( database ),
181
_transaction.begin();
188
_transaction.rollback();
195
//______________________________________________________________________________
200
* Commit the transaction
205
_transaction.commit();
210
//______________________________________________________________________________
214
/* the transaction */
217
/* have we released the transaction yet? */
223
} // namespace sqlite
226
#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_ */