From 7e5c360a8c8eee8ebe8b1c18e49be5b4af8dac57 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Sep 2021 14:25:28 +0100 Subject: Add JT recommended warnings --- libsqlitepp/sqlite-command.cpp | 46 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'libsqlitepp/sqlite-command.cpp') 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(sql.length()), &stmt, nullptr) != SQLITE_OK) { throw Error(conn->db); } } @@ -15,61 +15,54 @@ SQLite::Command::~Command() sqlite3_finalize(stmt); } +template 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(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(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(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(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(n + 1), s.data(), static_cast(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(n + 1)) != SQLITE_OK) { throw Error(c->db); } } -- cgit v1.2.3