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
|
#include "../../include/odhtdb/sql/Sql.hpp"
#include <sqlite3.h>
#include <exception>
#include <cassert>
namespace odhtdb
{
int SqlArg::bind(sqlite3_stmt *stmt, int paramIndex) const
{
switch(type)
{
case Type::DATA_VIEW:
return sqlite3_bind_blob(stmt, paramIndex, dataView.data, dataView.size, SQLITE_STATIC);
case Type::INT:
return sqlite3_bind_int(stmt, paramIndex, integer);
case Type::INT64:
return sqlite3_bind_int64(stmt, paramIndex, integer64);
case Type::UINT64: // TODO: Find a way to use u64 in sqlite
return sqlite3_bind_int64(stmt, paramIndex, uinteger64);
}
return SQLITE_OK;
}
SqlTransaction::SqlTransaction(sqlite3 *_db) :
db(_db)
{
assert(db);
sqlite3_exec(db, "BEGIN", 0, 0, 0);
}
SqlTransaction::~SqlTransaction()
{
if(std::uncaught_exception())
sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
}
void SqlTransaction::commit()
{
sqlite3_exec(db, "COMMIT", 0, 0, 0);
}
}
|