1 |
// Truck Computer Dooom! |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "sqlite3.hpp" |
8 |
|
9 |
namespace SQLite3 |
10 |
{ |
11 |
|
12 |
Connection::Connection(const std::string &db) |
13 |
{ |
14 |
CheckError(::sqlite3_open(db.c_str(), &connection), connection); |
15 |
} |
16 |
|
17 |
Connection::~Connection() |
18 |
{ |
19 |
CheckError(::sqlite3_close(connection), connection); |
20 |
} |
21 |
|
22 |
Statement::Statement(Connection &connection, const std::string &statement) : connection(connection) |
23 |
{ |
24 |
CheckError(::sqlite3_prepare_v2(connection.GetHandle(), statement.data(), statement.size(), &this->statement, NULL), connection.GetHandle()); |
25 |
} |
26 |
|
27 |
Statement::~Statement() |
28 |
{ |
29 |
::sqlite3_finalize(statement); |
30 |
} |
31 |
|
32 |
void Statement::Set(unsigned index, double value) |
33 |
{ |
34 |
CheckError(::sqlite3_bind_double(statement, index, value), connection.GetHandle()); |
35 |
} |
36 |
|
37 |
void Statement::Set(unsigned index, int value) |
38 |
{ |
39 |
CheckError(::sqlite3_bind_int(statement, index, value), connection.GetHandle()); |
40 |
} |
41 |
|
42 |
void Statement::Set(unsigned index, int64_t value) |
43 |
{ |
44 |
CheckError(::sqlite3_bind_int64(statement, index, value), connection.GetHandle()); |
45 |
} |
46 |
|
47 |
void Statement::Set(unsigned index, const Null &value) |
48 |
{ |
49 |
CheckError(::sqlite3_bind_null(statement, index), connection.GetHandle()); |
50 |
} |
51 |
|
52 |
void Statement::Set(unsigned index, const std::string &value) |
53 |
{ |
54 |
CheckError(::sqlite3_bind_text(statement, index, value.data(), value.size(), SQLITE_TRANSIENT), connection.GetHandle()); |
55 |
} |
56 |
|
57 |
} |