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