/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
 *
22 by edam
updated email and web addresses
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
1 by edam
- initial commit
5
 *
2 by edam
- further initial development
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
22 by edam
updated email and web addresses
7
 * See http://ed.am/dev/sqlite3cc for more information.
8
 *
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 * details.
1 by edam
- initial commit
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
		/**
22 by edam
updated email and web addresses
58
		 * Constructor that provides a connection upon which to act.
59
		 *
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
60
		 * @param connection reference to a connection
61
		 * @see sqlite3_db_mutex()
62
		 * @see sqlite3_mutex_enter()
63
		 */
64
		mutex_guard(
65
			connection &connection );
66
67
		~mutex_guard();
68
69
		/**
22 by edam
updated email and web addresses
70
		 * Release the mutex early.
71
		 *
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
72
		 * @see sqlite3_mutex_leave()
73
		 */
74
		void leave();
75
76
	private:
77
		sqlite3_mutex *_mutex;
78
	};
79
80
//______________________________________________________________________________
1 by edam
- initial commit
81
//                                                                 instantiation
82
public:
83
84
	/**
85
	 * Constructor that specifies the filename of a database to open.
22 by edam
updated email and web addresses
86
	 *
1 by edam
- initial commit
87
	 * @param filename the filename of the database file to open
88
	 * @throws database_error on error
89
	 */
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
90
	explicit connection(
1 by edam
- initial commit
91
		const std::string &filename );
92
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
93
	explicit connection();
94
	virtual ~connection();
1 by edam
- initial commit
95
96
//______________________________________________________________________________
97
//                                                              public interface
98
public:
99
100
	/**
101
	 * Open a database.
22 by edam
updated email and web addresses
102
	 *
1 by edam
- initial commit
103
	 * @param filename the filename of the database file to open
104
	 * @param flags flags appropriate for sqlite3_open_v2()
105
	 * @returns an sqlite error code
106
	 * @see sqlite3_open_v2()
107
	 */
108
	int open(
109
		const std::string &filename,
110
		int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE );
111
112
	/**
113
	 * Close an open database.
22 by edam
updated email and web addresses
114
	 *
1 by edam
- initial commit
115
	 * @throws database_error on error
116
	 * @see sqlite3_close()
117
	 */
118
	void close();
119
120
	/**
22 by edam
updated email and web addresses
121
	 * Execute an SQL statement.  An exception is thrown on error.
122
	 *
1 by edam
- initial commit
123
	 * @param sql an SQL statement in UTF-8
124
	 * @see sqlite3_exc()
125
	 */
10 by edam
- cleaned up test-main
126
	void exec(
1 by edam
- initial commit
127
		const std::string &sql );
128
129
	/**
22 by edam
updated email and web addresses
130
	 * Sets a default busy handler which will wait for the specified number of
131
	 * milliseconds.
132
	 *
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
133
	 * @param duration number of milliseconds to wait
1 by edam
- initial commit
134
	 * @returns an sqlite error code
135
	 * @see sqlite3_busy_timeout()
136
	 */
137
	int busy_timeout(
138
		int duration );
139
140
//______________________________________________________________________________
141
//                                                                implementation
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
142
private:
1 by edam
- initial commit
143
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
144
	friend class detail::basic_statement;
145
	friend class detail::basic_transaction;
2 by edam
- further initial development
146
	friend class command;
13 by edam
- made basic_statement::step() protected, for use by query and command only
147
	friend class sqlite_error;
148
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
149
	/** the connection handle */
1 by edam
- initial commit
150
	sqlite3 *_handle;
151
152
};
153
154
2 by edam
- further initial development
155
} // namespace sqlite
156
157
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
158
#endif /* SQLITE3CC_CONNECTION_H_ */