bzr branch
http://bzr.ed.am/sqlite3cc
1
by edam
- initial commit |
1 |
/* |
2 |
* database.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 DATABASE_HPP_ |
|
24 |
#define DATABASE_HPP_ |
|
25 |
||
26 |
||
27 |
#include <sqlite3.h> |
|
28 |
#include <boost/utility.hpp> |
|
29 |
||
30 |
||
31 |
namespace sqlite |
|
32 |
{ |
|
33 |
||
34 |
||
35 |
class statement; |
|
36 |
class transaction; |
|
37 |
||
38 |
||
39 |
class database |
|
40 |
: |
|
41 |
private boost::noncopyable |
|
42 |
{ |
|
43 |
//______________________________________________________________________________ |
|
44 |
// instantiation |
|
45 |
public: |
|
46 |
||
47 |
/** |
|
48 |
* Constructor that specifies the filename of a database to open. |
|
49 |
* @param filename the filename of the database file to open |
|
50 |
* @throws database_error on error |
|
51 |
*/ |
|
52 |
database( |
|
53 |
const std::string &filename ); |
|
54 |
||
55 |
database(); |
|
56 |
virtual ~database() throw( ); |
|
57 |
||
58 |
//______________________________________________________________________________ |
|
59 |
// public interface |
|
60 |
public: |
|
61 |
||
62 |
/** |
|
63 |
* Open a database. |
|
64 |
* @param filename the filename of the database file to open |
|
65 |
* @param flags flags appropriate for sqlite3_open_v2() |
|
66 |
* @returns an sqlite error code |
|
67 |
* @see sqlite3_open_v2() |
|
68 |
*/ |
|
69 |
int open( |
|
70 |
const std::string &filename, |
|
71 |
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE ); |
|
72 |
||
73 |
/** |
|
74 |
* Close an open database. |
|
75 |
* @throws database_error on error |
|
76 |
* @see sqlite3_close() |
|
77 |
*/ |
|
78 |
void close(); |
|
79 |
||
80 |
/** |
|
81 |
* Execute an SQL statement. |
|
82 |
* @param sql an SQL statement in UTF-8 |
|
83 |
* @return an sqlite error code |
|
84 |
* @see sqlite3_exc() |
|
85 |
*/ |
|
86 |
int exec( |
|
87 |
const std::string &sql ); |
|
88 |
||
89 |
/** |
|
90 |
* Sets a default busy handler which will |
|
91 |
* wait for the specified number of milliseconds. |
|
92 |
* @param milliseconds number of milliseconds to wait |
|
93 |
* @returns an sqlite error code |
|
94 |
* @see sqlite3_busy_timeout() |
|
95 |
*/ |
|
96 |
int busy_timeout( |
|
97 |
int duration ); |
|
98 |
||
99 |
//______________________________________________________________________________ |
|
100 |
// implementation |
|
101 |
private: |
|
102 |
||
103 |
friend class statement; |
|
104 |
friend class transaction; |
|
105 |
||
106 |
/** the database handle */ |
|
107 |
sqlite3 *_handle; |
|
108 |
||
109 |
}; |
|
110 |
||
111 |
||
112 |
} |
|
113 |
||
114 |
||
115 |
#endif /* DATABASE_HPP_ */ |