1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include "sqlite-connection.h"
#include "sqlite-error.h"
#include "sqlite-selectcommand.h"
#include "sqlite-modifycommand.h"
NAMEDFACTORY("sqlite", SQLite::Connection, DB::ConnectionFactory);
SQLite::ConnectionError::ConnectionError(sqlite3 * db) :
SQLite::Error(db)
{
}
SQLite::Connection::Connection(const std::string & str)
{
if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) {
ConnectionError err(db);
sqlite3_close(db);
throw err;
}
}
SQLite::Connection::~Connection()
{
sqlite3_close(db);
}
void
SQLite::Connection::beginTxInt()
{
if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
throw Error(db);
}
}
void
SQLite::Connection::commitTxInt()
{
if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
throw Error(db);
}
}
void
SQLite::Connection::rollbackTxInt()
{
if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
throw Error(db);
}
}
DB::BulkDeleteStyle
SQLite::Connection::bulkDeleteStyle() const
{
return DB::BulkDeleteUsingUsingAlias;
}
DB::BulkUpdateStyle
SQLite::Connection::bulkUpdateStyle() const
{
return DB::BulkUpdateUsingJoin;
}
void
SQLite::Connection::ping() const
{
// Can this fail?
}
DB::SelectCommandPtr
SQLite::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &)
{
return std::make_shared<SelectCommand>(this, sql);
}
DB::ModifyCommandPtr
SQLite::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr &)
{
return std::make_shared<ModifyCommand>(this, sql);
}
int64_t
SQLite::Connection::insertId()
{
return sqlite3_last_insert_rowid(db);
}
|