From 5dd91c7b80443c1f0e747088159c4d8b78d1856d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 24 Dec 2015 04:13:24 +0000 Subject: SQLite files prefixed with sqlite- --- libsqlitepp/sqlite-command.cpp | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 libsqlitepp/sqlite-command.cpp (limited to 'libsqlitepp/sqlite-command.cpp') diff --git a/libsqlitepp/sqlite-command.cpp b/libsqlitepp/sqlite-command.cpp new file mode 100644 index 0000000..48563fa --- /dev/null +++ b/libsqlitepp/sqlite-command.cpp @@ -0,0 +1,105 @@ +#include "sqlite-command.h" +#include "sqlite-connection.h" +#include +#include + +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::bindParamB(unsigned int, bool) +{ + throw Error("Not supported"); +} +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)); + } +} + -- cgit v1.2.3