summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-command.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsqlitepp/sqlite-command.cpp')
-rw-r--r--libsqlitepp/sqlite-command.cpp46
1 files changed, 20 insertions, 26 deletions
diff --git a/libsqlitepp/sqlite-command.cpp b/libsqlitepp/sqlite-command.cpp
index 124b5d0..694c5d2 100644
--- a/libsqlitepp/sqlite-command.cpp
+++ b/libsqlitepp/sqlite-command.cpp
@@ -5,7 +5,7 @@
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) {
+ if (sqlite3_prepare_v2(conn->db, sql.c_str(), static_cast<int>(sql.length()), &stmt, nullptr) != SQLITE_OK) {
throw Error(conn->db);
}
}
@@ -15,61 +15,54 @@ SQLite::Command::~Command()
sqlite3_finalize(stmt);
}
+template<typename V, typename BinderFunction>
void
-SQLite::Command::bindParamI(unsigned int n, int v)
+SQLite::Command::bindWith(unsigned int n, const V & v, BinderFunction binder) const
{
- if (sqlite3_bind_int(stmt, (int)n + 1, v) != SQLITE_OK) {
+ if (binder(stmt, static_cast<int>(n + 1), v) != SQLITE_OK) {
throw Error(c->db);
}
}
+
+void
+SQLite::Command::bindParamI(unsigned int n, int v)
+{
+ bindWith(n, v, sqlite3_bind_int);
+}
void
SQLite::Command::bindParamI(unsigned int n, long int v)
{
- if (sqlite3_bind_int64(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, v, sqlite3_bind_int64);
}
void
SQLite::Command::bindParamI(unsigned int n, long long int v)
{
- if (sqlite3_bind_int64(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, v, sqlite3_bind_int64);
}
void
SQLite::Command::bindParamI(unsigned int n, unsigned int v)
{
- if (sqlite3_bind_int64(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, v, sqlite3_bind_int64);
}
void
SQLite::Command::bindParamI(unsigned int n, long unsigned int v)
{
- if (sqlite3_bind_int64(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, static_cast<sqlite3_int64>(v), sqlite3_bind_int64);
}
void
SQLite::Command::bindParamI(unsigned int n, long long unsigned int v)
{
- if (sqlite3_bind_int64(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, static_cast<sqlite3_int64>(v), sqlite3_bind_int64);
}
void
SQLite::Command::bindParamF(unsigned int n, double v)
{
- if (sqlite3_bind_double(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, v, sqlite3_bind_double);
}
void
SQLite::Command::bindParamF(unsigned int n, float v)
{
- if (sqlite3_bind_double(stmt, (int)n + 1, v) != SQLITE_OK) {
- throw Error(c->db);
- }
+ bindWith(n, static_cast<double>(v), sqlite3_bind_double);
}
void
SQLite::Command::bindParamS(unsigned int n, const Glib::ustring & s)
@@ -79,7 +72,8 @@ SQLite::Command::bindParamS(unsigned int n, const Glib::ustring & s)
void
SQLite::Command::bindParamS(unsigned int n, const std::string_view & s)
{
- if (sqlite3_bind_text(stmt, (int)n + 1, s.data(), s.length(), SQLITE_STATIC) != SQLITE_OK) {
+ if (sqlite3_bind_text(stmt, static_cast<int>(n + 1), s.data(), static_cast<int>(s.length()), SQLITE_STATIC)
+ != SQLITE_OK) {
throw Error(c->db);
}
}
@@ -101,7 +95,7 @@ SQLite::Command::bindParamT(unsigned int, const boost::posix_time::ptime &)
void
SQLite::Command::bindNull(unsigned int n)
{
- if (sqlite3_bind_null(stmt, (int)n + 1) != SQLITE_OK) {
+ if (sqlite3_bind_null(stmt, static_cast<int>(n + 1)) != SQLITE_OK) {
throw Error(c->db);
}
}