/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc
1 by edam
- initial commit
1
/*
2
 * transaction.hpp
3
 *
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
 *
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.
8
 *
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.
13
 *
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.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef TRANSACTION_HPP_
24
#define TRANSACTION_HPP_
25
26
27
#include <boost/utility.hpp>
28
29
30
namespace sqlite
31
{
32
33
34
class database;
35
36
37
class transaction
38
	:
39
	private boost::noncopyable
40
{
41
//______________________________________________________________________________
42
//                                                                 instantiation
43
public:
44
45
	/**
46
	 * Constructor that provides a database upon which to act
47
	 * @param database a database
48
	 */
49
	transaction(
50
		database &database );
51
52
	virtual ~transaction() throw( );
53
54
protected:
55
56
	/**
57
	 * Constructor that provides a way for deriving classes to override the SQL
58
	 * executed in beginning and rolling-back a transaction during construction
59
	 * and destruction.
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.
64
	 */
65
	transaction(
66
		database &database,
67
		const std::string &begin_sql,
68
		const std::string &rollback_sql = "" );
69
70
//______________________________________________________________________________
71
//                                                              public interface
72
73
	/**
74
	 * Commit the transaction
75
	 */
76
	virtual void commit();
77
78
	/**
79
	 * Rollback the transaction
80
	 */
81
	void rollback();
82
83
//______________________________________________________________________________
84
//                                                                implementation
85
protected:
86
87
	/** the database */
88
	database &_database;
89
90
	/** the SQL used to rollback the transaction, or empty to use default */
91
	std::string _rollback_sql;
92
93
};
94
95
96
////////////////////////////////////////////////////////////////////////////////
97
98
99
class exclusive_transaction
100
	:
101
	public transaction
102
{
103
//______________________________________________________________________________
104
//                                                                 instantiation
105
public:
106
107
	/**
108
	 * Constructor that provides a database upon which to act
109
	 * @param database a database
110
	 */
111
	exclusive_transaction(
112
		database &database );
113
114
};
115
116
117
}
118
119
120
#endif /* TRANSACTION_HPP_ */