From ef16da27477a2a234cab8aed1e072555d6bb410e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 24 Feb 2019 13:30:22 +0000 Subject: Bring inline with clang-tidy checks --- libsqlitepp/sqlite-command.cpp | 9 +++++---- libsqlitepp/sqlite-connection.cpp | 14 +++++++------- libsqlitepp/sqlite-error.cpp | 4 ++-- libsqlitepp/sqlite-error.h | 2 +- libsqlitepp/sqlite-mock.cpp | 8 ++++---- libsqlitepp/sqlite-modifycommand.cpp | 6 +----- libsqlitepp/sqlite-modifycommand.h | 5 ----- libsqlitepp/sqlite-selectcommand.cpp | 2 +- 8 files changed, 21 insertions(+), 29 deletions(-) diff --git a/libsqlitepp/sqlite-command.cpp b/libsqlitepp/sqlite-command.cpp index adaf41e..0ae59d1 100644 --- a/libsqlitepp/sqlite-command.cpp +++ b/libsqlitepp/sqlite-command.cpp @@ -1,13 +1,14 @@ #include "sqlite-command.h" #include "sqlite-connection.h" -#include -#include +#include +#include SQLite::Command::Command(const Connection * conn, const std::string & sql) : DB::Command(sql), - c(conn) + c(conn), + stmt(nullptr) { - if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, NULL) != SQLITE_OK) { + if (sqlite3_prepare_v2(conn->db, sql.c_str(), sql.length(), &stmt, nullptr) != SQLITE_OK) { throw Error(conn->db); } } diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp index 1539668..a93cad7 100644 --- a/libsqlitepp/sqlite-connection.cpp +++ b/libsqlitepp/sqlite-connection.cpp @@ -10,12 +10,12 @@ SQLite::ConnectionError::ConnectionError(sqlite3 * db) : { } -SQLite::Connection::Connection(const std::string & str) +SQLite::Connection::Connection(const std::string & str) : + db(nullptr) { if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) { - ConnectionError err(db); - sqlite3_close(db); - throw err; + auto dbp = std::unique_ptr(db, &sqlite3_close); + throw ConnectionError(dbp.get()); } } @@ -27,7 +27,7 @@ SQLite::Connection::~Connection() void SQLite::Connection::beginTxInt() { - if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { + if (sqlite3_exec(db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) { throw Error(db); } } @@ -35,7 +35,7 @@ SQLite::Connection::beginTxInt() void SQLite::Connection::commitTxInt() { - if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { + if (sqlite3_exec(db, "COMMIT TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) { throw Error(db); } } @@ -43,7 +43,7 @@ SQLite::Connection::commitTxInt() void SQLite::Connection::rollbackTxInt() { - if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { + if (sqlite3_exec(db, "ROLLBACK TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) { throw Error(db); } } diff --git a/libsqlitepp/sqlite-error.cpp b/libsqlitepp/sqlite-error.cpp index 03ffac4..f1c62e5 100644 --- a/libsqlitepp/sqlite-error.cpp +++ b/libsqlitepp/sqlite-error.cpp @@ -1,5 +1,5 @@ #include "sqlite-error.h" -#include +#include SQLite::Error::Error(sqlite3 * db) : msg(sqlite3_errmsg(db)) @@ -7,7 +7,7 @@ SQLite::Error::Error(sqlite3 * db) : } std::string -SQLite::Error::message() const throw() +SQLite::Error::message() const noexcept { return msg; } diff --git a/libsqlitepp/sqlite-error.h b/libsqlitepp/sqlite-error.h index a42d2e4..74cff19 100644 --- a/libsqlitepp/sqlite-error.h +++ b/libsqlitepp/sqlite-error.h @@ -11,7 +11,7 @@ namespace SQLite { public: Error(sqlite3 *); - std::string message() const throw() override; + std::string message() const noexcept override; private: std::string msg; diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp index 510b209..4a96e35 100644 --- a/libsqlitepp/sqlite-mock.cpp +++ b/libsqlitepp/sqlite-mock.cpp @@ -7,9 +7,9 @@ NAMEDFACTORY("sqlite", SQLite::Mock, DB::MockDatabaseFactory); namespace SQLite { Mock::Mock(const std::string & root, const std::string & name, const std::vector & ss) : - testDbPath(std::filesystem::path(root) / name / boost::lexical_cast(getpid()) / boost::lexical_cast(++DB::MockDatabase::mocked)) + testDbPath(std::filesystem::path(root) / name / std::to_string(getpid()) / std::to_string(++DB::MockDatabase::mocked)) { - CreateNewDatabase(); + Mock::CreateNewDatabase(); PlaySchemaScripts(ss); } @@ -26,7 +26,7 @@ Mock::openConnection() const Mock::~Mock() { - DropDatabase(); + Mock::DropDatabase(); } void Mock::DropDatabase() const @@ -37,7 +37,7 @@ void Mock::DropDatabase() const void Mock::CreateNewDatabase() const { std::filesystem::create_directories(testDbPath.parent_path()); - openConnection(); // Triggers file creation + Mock::openConnection(); // Triggers file creation } } diff --git a/libsqlitepp/sqlite-modifycommand.cpp b/libsqlitepp/sqlite-modifycommand.cpp index d5f44cc..25c771c 100644 --- a/libsqlitepp/sqlite-modifycommand.cpp +++ b/libsqlitepp/sqlite-modifycommand.cpp @@ -1,6 +1,6 @@ #include "sqlite-modifycommand.h" #include "sqlite-error.h" -#include +#include #include "sqlite-connection.h" SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql) : @@ -10,10 +10,6 @@ SQLite::ModifyCommand::ModifyCommand(const Connection * conn, const std::string { } -SQLite::ModifyCommand::~ModifyCommand() -{ -} - unsigned int SQLite::ModifyCommand::execute(bool anc) { diff --git a/libsqlitepp/sqlite-modifycommand.h b/libsqlitepp/sqlite-modifycommand.h index c71dd1f..139e698 100644 --- a/libsqlitepp/sqlite-modifycommand.h +++ b/libsqlitepp/sqlite-modifycommand.h @@ -9,13 +9,8 @@ namespace SQLite { class ModifyCommand : public DB::ModifyCommand, public Command { public: ModifyCommand(const Connection *, const std::string & sql); - virtual ~ModifyCommand(); unsigned int execute(bool) override; - - private: - void prepare() const; - mutable bool prepared; }; } diff --git a/libsqlitepp/sqlite-selectcommand.cpp b/libsqlitepp/sqlite-selectcommand.cpp index 909dc5c..197356c 100644 --- a/libsqlitepp/sqlite-selectcommand.cpp +++ b/libsqlitepp/sqlite-selectcommand.cpp @@ -1,7 +1,7 @@ #include "sqlite-selectcommand.h" #include "sqlite-connection.h" #include "sqlite-error.h" -#include +#include #include #include -- cgit v1.2.3