ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/sqlite3.hpp
Revision: 45
Committed: 2008-03-06T18:12:54-08:00 (14 years, 7 months ago) by douglas
File size: 1423 byte(s)
Log Message:
Beginnings of an sqlite3 api ala Menes' dbi.

File Contents

# Content
1 // Truck Computer Dooom!
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #ifndef _sqlite3_hpp_
8 #define _sqlite3_hpp_
9
10 #include <string>
11
12 #include <sqlite3.h>
13
14 namespace SQLite3
15 {
16
17 class Error : public std::exception
18 {
19 std::string message;
20
21 public:
22 Error(::sqlite3 *connection) : message(::sqlite3_errmsg(connection)) {}
23 virtual ~Error() throw() {}
24
25 virtual const char *what() const throw()
26 {
27 return message.c_str();
28 }
29 };
30
31 inline int CheckError(int code, ::sqlite3 *connection)
32 {
33 if (code != SQLITE_OK)
34 throw Error(connection);
35
36 return code;
37 }
38
39 class ResultSet;
40 class Statement;
41
42 class Connection
43 {
44 ::sqlite3 *connection;
45
46 public:
47 Connection(const std::string &db);
48 ~Connection();
49
50 ResultSet Execute(const std::string &statement);
51 Statement Parse(const std::string &statement);
52
53 std::string Save();
54 void Commit(const std::string &point);
55 void Abort(const std::string &point);
56
57 inline ::sqlite3 *GetHandle() const
58 {
59 return connection;
60 }
61 };
62
63 class ResultSet
64 {
65 Connection &connection;
66 };
67
68 class Null {};
69
70 class Statement
71 {
72 Connection &connection;
73 ::sqlite3_stmt *statement;
74
75 public:
76 Statement(Connection &connection, const std::string &statement);
77 ~Statement();
78
79 void Set(unsigned index, double value);
80 void Set(unsigned index, int value);
81 void Set(unsigned index, int64_t value);
82 void Set(unsigned index, const Null &value);
83 void Set(unsigned index, const std::string &value);
84 };
85
86 }
87
88 #endif//_sqlite3_hpp_

Properties

Name Value
svn:keywords Id