diff options
Diffstat (limited to 'libsqlitepp')
-rw-r--r-- | libsqlitepp/Jamfile.jam | 15 | ||||
-rw-r--r-- | libsqlitepp/sqlite-command.cpp | 46 | ||||
-rw-r--r-- | libsqlitepp/sqlite-command.h | 3 | ||||
-rw-r--r-- | libsqlitepp/sqlite-connection.cpp | 2 | ||||
-rw-r--r-- | libsqlitepp/sqlite-mock.cpp | 2 | ||||
-rw-r--r-- | libsqlitepp/sqlite-modifycommand.cpp | 2 | ||||
-rw-r--r-- | libsqlitepp/sqlite-selectcommand.cpp | 14 | ||||
-rw-r--r-- | libsqlitepp/unittests/testsqlite.cpp | 4 |
8 files changed, 50 insertions, 38 deletions
diff --git a/libsqlitepp/Jamfile.jam b/libsqlitepp/Jamfile.jam index 84e8c85..951b648 100644 --- a/libsqlitepp/Jamfile.jam +++ b/libsqlitepp/Jamfile.jam @@ -17,6 +17,21 @@ project <variant>release:<lto>on <variant>debug:<warnings>extra <variant>debug:<warnings-as-errors>on + <variant>debug:<cflags>-Wnon-virtual-dtor + <variant>debug:<cflags>-Wold-style-cast + <variant>debug:<cflags>-Wcast-align + <variant>debug:<cflags>-Wunused + <variant>debug:<cflags>-Woverloaded-virtual + <variant>debug:<cflags>-Wpedantic + <variant>debug:<cflags>-Wconversion + <variant>debug:<cflags>-Wsign-conversion + <variant>debug:<cflags>-Wnull-dereference + <variant>debug:<cflags>-Wdouble-promotion + <variant>debug:<cflags>-Wformat=2 + <toolset>gcc,<variant>debug:<cflags>-Wduplicated-cond + <toolset>gcc,<variant>debug:<cflags>-Wduplicated-branches + <toolset>gcc,<variant>debug:<cflags>-Wlogical-op + <toolset>gcc,<variant>debug:<cflags>-Wuseless-cast <variant>coverage:<coverage>on ; 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); } } diff --git a/libsqlitepp/sqlite-command.h b/libsqlitepp/sqlite-command.h index abf02ee..1bf93c4 100644 --- a/libsqlitepp/sqlite-command.h +++ b/libsqlitepp/sqlite-command.h @@ -32,6 +32,9 @@ namespace SQLite { void bindNull(unsigned int) override; protected: + template<typename V, typename BinderFunction> + void bindWith(unsigned int n, const V & v, BinderFunction binder) const; + const Connection * c; sqlite3_stmt * stmt; }; diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp index 99006dc..e1a6de7 100644 --- a/libsqlitepp/sqlite-connection.cpp +++ b/libsqlitepp/sqlite-connection.cpp @@ -3,7 +3,7 @@ #include "sqlite-modifycommand.h" #include "sqlite-selectcommand.h" -NAMEDFACTORY("sqlite", SQLite::Connection, DB::ConnectionFactory); +NAMEDFACTORY("sqlite", SQLite::Connection, DB::ConnectionFactory) SQLite::ConnectionError::ConnectionError(sqlite3 * db) : SQLite::Error(db) { } diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp index 4772bcc..11f4f90 100644 --- a/libsqlitepp/sqlite-mock.cpp +++ b/libsqlitepp/sqlite-mock.cpp @@ -2,7 +2,7 @@ #include "sqlite-connection.h" #include <boost/lexical_cast.hpp> -NAMEDFACTORY("sqlite", SQLite::Mock, DB::MockDatabaseFactory); +NAMEDFACTORY("sqlite", SQLite::Mock, DB::MockDatabaseFactory) namespace SQLite { diff --git a/libsqlitepp/sqlite-modifycommand.cpp b/libsqlitepp/sqlite-modifycommand.cpp index 868f187..df859ca 100644 --- a/libsqlitepp/sqlite-modifycommand.cpp +++ b/libsqlitepp/sqlite-modifycommand.cpp @@ -15,7 +15,7 @@ SQLite::ModifyCommand::execute(bool anc) sqlite3_reset(stmt); throw Error(c->db); } - unsigned int rows = sqlite3_changes(c->db); + unsigned int rows = static_cast<unsigned int>(sqlite3_changes(c->db)); sqlite3_reset(stmt); if (rows == 0 && !anc) { throw DB::NoRowsAffected(); diff --git a/libsqlitepp/sqlite-selectcommand.cpp b/libsqlitepp/sqlite-selectcommand.cpp index c4a1096..e360dcd 100644 --- a/libsqlitepp/sqlite-selectcommand.cpp +++ b/libsqlitepp/sqlite-selectcommand.cpp @@ -13,23 +13,23 @@ namespace SQLite { [[nodiscard]] bool isNull() const override { - return (SQLITE_NULL == sqlite3_column_type(stmt, (int)colNo)); + return (SQLITE_NULL == sqlite3_column_type(stmt, static_cast<int>(colNo))); } void apply(DB::HandleField & h) const override { - switch (sqlite3_column_type(stmt, (int)colNo)) { + switch (sqlite3_column_type(stmt, static_cast<int>(colNo))) { case SQLITE_INTEGER: - h.integer(sqlite3_column_int64(stmt, (int)colNo)); + h.integer(sqlite3_column_int64(stmt, static_cast<int>(colNo))); return; case SQLITE_FLOAT: - h.floatingpoint(sqlite3_column_double(stmt, (int)colNo)); + h.floatingpoint(sqlite3_column_double(stmt, static_cast<int>(colNo))); return; case SQLITE_TEXT: { - auto t = sqlite3_column_text(stmt, (int)colNo); - auto l = sqlite3_column_bytes(stmt, (int)colNo); - h.string({reinterpret_cast<const char *>(t), (std::size_t)l}); + auto t = sqlite3_column_text(stmt, static_cast<int>(colNo)); + auto l = sqlite3_column_bytes(stmt, static_cast<int>(colNo)); + h.string({reinterpret_cast<const char *>(t), static_cast<std::size_t>(l)}); return; } case SQLITE_NULL: diff --git a/libsqlitepp/unittests/testsqlite.cpp b/libsqlitepp/unittests/testsqlite.cpp index 81127c8..37f17ce 100644 --- a/libsqlitepp/unittests/testsqlite.cpp +++ b/libsqlitepp/unittests/testsqlite.cpp @@ -16,7 +16,7 @@ public: BOOST_GLOBAL_FIXTURE(StandardMockDatabase); -BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore); +BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore) BOOST_AUTO_TEST_CASE(transactions) { @@ -63,4 +63,4 @@ BOOST_AUTO_TEST_CASE(bindAndSelect) BOOST_REQUIRE_EQUAL(1, rows); } -BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_SUITE_END() |