summaryrefslogtreecommitdiff
path: root/libsqlitepp/command.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-04-30 00:27:27 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-04-30 00:27:27 +0100
commitf634bafc38bb948e41f829b16f03e2f0b8ee8f93 (patch)
treec4f8ff17614b68531355e8047d81e96719101d10 /libsqlitepp/command.cpp
parentIgnore Vim swap files (diff)
downloadlibdbpp-sqlite-f634bafc38bb948e41f829b16f03e2f0b8ee8f93.tar.bz2
libdbpp-sqlite-f634bafc38bb948e41f829b16f03e2f0b8ee8f93.tar.xz
libdbpp-sqlite-f634bafc38bb948e41f829b16f03e2f0b8ee8f93.zip
Adds support for SQLite, SQLite mocking and some basic tests
Diffstat (limited to 'libsqlitepp/command.cpp')
-rw-r--r--libsqlitepp/command.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/libsqlitepp/command.cpp b/libsqlitepp/command.cpp
new file mode 100644
index 0000000..ce2758b
--- /dev/null
+++ b/libsqlitepp/command.cpp
@@ -0,0 +1,100 @@
+#include "command.h"
+#include "connection.h"
+#include <stdlib.h>
+#include <string.h>
+
+SQLite::Command::Command(const Connection * conn, const std::string & sql) :
+ DB::Command(sql),
+ c(conn)
+{
+ if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, NULL) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(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(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamI(unsigned int n, long int v)
+{
+ if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(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(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamI(unsigned int n, unsigned int v)
+{
+ if (sqlite3_bind_int64(stmt, n + 1, v) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(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(sqlite3_errmsg(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(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamF(unsigned int n, double v)
+{
+ if (sqlite3_bind_double(stmt, n + 1, v) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamF(unsigned int n, float v)
+{
+ if (sqlite3_bind_double(stmt, n + 1, v) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamS(unsigned int n, const Glib::ustring & s)
+{
+ if (sqlite3_bind_text(stmt, n + 1, s.c_str(), s.length(), SQLITE_STATIC) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(c->db));
+ }
+}
+void
+SQLite::Command::bindParamT(unsigned int, const boost::posix_time::time_duration &)
+{
+ throw Error("Not supported");
+}
+void
+SQLite::Command::bindParamT(unsigned int, const boost::posix_time::ptime &)
+{
+ throw Error("Not supported");
+}
+void
+SQLite::Command::bindNull(unsigned int n)
+{
+ if (sqlite3_bind_null(stmt, n + 1) != SQLITE_OK) {
+ throw Error(sqlite3_errmsg(c->db));
+ }
+}
+