/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc
1 by edam
- initial commit
1
/*
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
2
 * connection.h
1 by edam
- initial commit
3
 *
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
 *
2 by edam
- further initial development
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.
1 by edam
- initial commit
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
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
23
#ifndef SQLITE3CC_CONNECTION_H_
24
#define SQLITE3CC_CONNECTION_H_
1 by edam
- initial commit
25
26
27
#include <sqlite3.h>
28
#include <boost/utility.hpp>
11 by edam
- update TODO
29
#include <string>
1 by edam
- initial commit
30
31
32
namespace sqlite
33
{
34
35
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
36
namespace detail {
37
	class basic_statement;
38
	class basic_transaction;
39
}
40
41
42
class connection
1 by edam
- initial commit
43
	:
44
	private boost::noncopyable
45
{
46
//______________________________________________________________________________
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
47
//                                                                         types
48
public:
49
50
	/**
51
	 * Class to provide a scope lock for the connection mutex
52
	 */
53
	class mutex_guard
54
	{
55
	public:
56
57
		/**
58
		 * Constructor that provides a connection upon which to act
59
		 * @param connection reference to a connection
60
		 * @see sqlite3_db_mutex()
61
		 * @see sqlite3_mutex_enter()
62
		 */
63
		mutex_guard(
64
			connection &connection );
65
66
		~mutex_guard();
67
68
		/**
69
		 * Release the mutex early
70
		 * @see sqlite3_mutex_leave()
71
		 */
72
		void leave();
73
74
	private:
75
		sqlite3_mutex *_mutex;
76
	};
77
78
//______________________________________________________________________________
1 by edam
- initial commit
79
//                                                                 instantiation
80
public:
81
82
	/**
83
	 * Constructor that specifies the filename of a database to open.
84
	 * @param filename the filename of the database file to open
85
	 * @throws database_error on error
86
	 */
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
87
	explicit connection(
1 by edam
- initial commit
88
		const std::string &filename );
89
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
90
	explicit connection();
91
	virtual ~connection();
1 by edam
- initial commit
92
93
//______________________________________________________________________________
94
//                                                              public interface
95
public:
96
97
	/**
98
	 * Open a database.
99
	 * @param filename the filename of the database file to open
100
	 * @param flags flags appropriate for sqlite3_open_v2()
101
	 * @returns an sqlite error code
102
	 * @see sqlite3_open_v2()
103
	 */
104
	int open(
105
		const std::string &filename,
106
		int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE );
107
108
	/**
109
	 * Close an open database.
110
	 * @throws database_error on error
111
	 * @see sqlite3_close()
112
	 */
113
	void close();
114
115
	/**
10 by edam
- cleaned up test-main
116
	 * Execute an SQL statement. An exception is thrown on error.
1 by edam
- initial commit
117
	 * @param sql an SQL statement in UTF-8
118
	 * @see sqlite3_exc()
119
	 */
10 by edam
- cleaned up test-main
120
	void exec(
1 by edam
- initial commit
121
		const std::string &sql );
122
123
	/**
124
	 * Sets a default busy handler which will
125
	 * wait for the specified number of milliseconds.
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
126
	 * @param duration number of milliseconds to wait
1 by edam
- initial commit
127
	 * @returns an sqlite error code
128
	 * @see sqlite3_busy_timeout()
129
	 */
130
	int busy_timeout(
131
		int duration );
132
133
//______________________________________________________________________________
134
//                                                                implementation
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
135
private:
1 by edam
- initial commit
136
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
137
	friend class detail::basic_statement;
138
	friend class detail::basic_transaction;
2 by edam
- further initial development
139
	friend class command;
13 by edam
- made basic_statement::step() protected, for use by query and command only
140
	friend class sqlite_error;
141
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
142
	/** the connection handle */
1 by edam
- initial commit
143
	sqlite3 *_handle;
144
145
};
146
147
2 by edam
- further initial development
148
} // namespace sqlite
149
150
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
151
#endif /* SQLITE3CC_CONNECTION_H_ */