summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-command.cpp
blob: 0ae59d1db57ee2e710e8b39e76fb7266e6a7a8ce (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "sqlite-command.h"
#include "sqlite-connection.h"
#include <cstdlib>
#include <cstring>

SQLite::Command::Command(const Connection * conn, const std::string & sql) :
	DB::Command(sql),
	c(conn),
	stmt(nullptr)
{
	if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, nullptr) != SQLITE_OK) {
		throw Error(conn->db);
	}
}

SQLite::Command::~Command()
{
	sqlite3_finalize(stmt);
}

void
SQLite::Command::bindParamI(unsigned int n, int v)
{
	if (sqlite3_bind_int(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamI(unsigned int n, long int v)
{
	if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamI(unsigned int n, long long int v)
{
	if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamI(unsigned int n, unsigned int v)
{
	if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamI(unsigned int n, long unsigned int v)
{
	if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamI(unsigned int n, long long unsigned int v)
{
	if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamF(unsigned int n, double v)
{
	if (sqlite3_bind_double(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamF(unsigned int n, float v)
{
	if (sqlite3_bind_double(stmt, n + 1, v) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamS(unsigned int n, const Glib::ustring & s)
{
	return bindParamS(n, std::string_view(s.raw()));
}
void
SQLite::Command::bindParamS(unsigned int n, const std::string_view & s)
{
	if (sqlite3_bind_text(stmt, n + 1, s.data(), s.length(), SQLITE_STATIC) != SQLITE_OK) {
		throw Error(c->db);
	}
}
void
SQLite::Command::bindParamB(unsigned int, bool)
{
	throw DB::ParameterTypeNotSupported();
}
void
SQLite::Command::bindParamT(unsigned int, const boost::posix_time::time_duration &)
{
	throw DB::ParameterTypeNotSupported();
}
void
SQLite::Command::bindParamT(unsigned int, const boost::posix_time::ptime &)
{
	throw DB::ParameterTypeNotSupported();
}
void
SQLite::Command::bindNull(unsigned int n)
{
	if (sqlite3_bind_null(stmt, n + 1) != SQLITE_OK) {
		throw Error(c->db);
	}
}