From 4117377db83f398c4d7be4085fe5a597299456c4 Mon Sep 17 00:00:00 2001 From: Kacperos155 Date: Mon, 25 Jul 2022 20:26:26 +0200 Subject: [PATCH] Rename RowExecutor to StatementExecutor --- CMakeLists.txt | 4 +- include/SQLiteCpp/Column.h | 4 +- include/SQLiteCpp/Statement.h | 4 +- .../{RowExecutor.h => StatementExecutor.h} | 30 ++++++------- src/Column.cpp | 2 +- src/Statement.cpp | 2 +- ...{RowExecutor.cpp => StatementExecutor.cpp} | 44 +++++++++---------- 7 files changed, 45 insertions(+), 45 deletions(-) rename include/SQLiteCpp/{RowExecutor.h => StatementExecutor.h} (92%) rename src/{RowExecutor.cpp => StatementExecutor.cpp} (79%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a4b7c0..535cf760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,9 +106,9 @@ set(SQLITECPP_SRC ${PROJECT_SOURCE_DIR}/src/Database.cpp ${PROJECT_SOURCE_DIR}/src/Exception.cpp ${PROJECT_SOURCE_DIR}/src/Row.cpp - ${PROJECT_SOURCE_DIR}/src/RowExecutor.cpp ${PROJECT_SOURCE_DIR}/src/Savepoint.cpp ${PROJECT_SOURCE_DIR}/src/Statement.cpp + ${PROJECT_SOURCE_DIR}/src/StatementExecutor.cpp ${PROJECT_SOURCE_DIR}/src/Transaction.cpp ) source_group(src FILES ${SQLITECPP_SRC}) @@ -122,9 +122,9 @@ set(SQLITECPP_INC ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Database.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Exception.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Row.h - ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/RowExecutor.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Savepoint.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Statement.h + ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/StatementExecutor.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Transaction.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/VariadicBind.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/ExecuteMany.h diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 92429320..2d83e338 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -55,7 +55,7 @@ class Column * * @throws Exception is thrown in case of error, then the Column object is NOT constructed. */ - explicit Column(const RowExecutor::TStatementPtr& aStmtPtr, int aIndex); + explicit Column(const StatementExecutor::TStatementPtr& aStmtPtr, int aIndex); /** * @brief Return a pointer to the named assigned to this result column (potentially aliased) @@ -226,7 +226,7 @@ class Column } private: - RowExecutor::TStatementPtr mStmtPtr; ///< Shared Pointer to the prepared SQLite Statement Object + StatementExecutor::TStatementPtr mStmtPtr; ///< Shared Pointer to the prepared SQLite Statement Object int mIndex; ///< Index of the column in the row of result, starting at 0 }; diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 8226c5a4..433afdb9 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -10,7 +10,7 @@ */ #pragma once -#include +#include #include #include // SQLITECPP_PURE_FUNC @@ -46,7 +46,7 @@ class Column; * because of the way it shares the underling SQLite precompiled statement * in a custom shared pointer (See the inner class "Statement::Ptr"). */ -class Statement : public RowExecutor +class Statement : public StatementExecutor { public: /** diff --git a/include/SQLiteCpp/RowExecutor.h b/include/SQLiteCpp/StatementExecutor.h similarity index 92% rename from include/SQLiteCpp/RowExecutor.h rename to include/SQLiteCpp/StatementExecutor.h index f2f14ca3..52fa8856 100644 --- a/include/SQLiteCpp/RowExecutor.h +++ b/include/SQLiteCpp/StatementExecutor.h @@ -1,5 +1,5 @@ /** - * @file RowExecutor.h + * @file StatementExecutor.h * @ingroup SQLiteCpp * @brief Step executor for SQLite prepared Statement Object * @@ -33,7 +33,7 @@ extern const int OK; ///< SQLITE_OK * inherit this class to create your own Statement executor class. * Either way you should look at SQLite::Statement documentation * -* Thread-safety: a RowExecutor object shall not be shared by multiple threads, because : +* Thread-safety: a StatementExecutor object shall not be shared by multiple threads, because : * 1) in the SQLite "Thread Safe" mode, "SQLite can be safely used by multiple threads * provided that no single database connection is used simultaneously in two or more threads." * 2) the SQLite "Serialized" mode is not supported by SQLiteC++, @@ -41,7 +41,7 @@ extern const int OK; ///< SQLITE_OK * in a custom shared pointer (See the inner class "Statement::Ptr"). * TODO Test Serialized mode after all changes to pointers */ -class RowExecutor +class StatementExecutor { public: /// Shared pointer to SQLite Prepared Statement Object @@ -50,19 +50,19 @@ class RowExecutor /// Weak pointer to SQLite Prepared Statement Object using TStatementWeakPtr = std::weak_ptr; - /// Shared pointer to SQLite RowExecutor - using TRowPtr = std::shared_ptr; + /// Shared pointer to SQLite StatementExecutor + using TRowPtr = std::shared_ptr; - /// Weak pointer to SQLite RowExecutor - using TRowWeakPtr = std::weak_ptr; + /// Weak pointer to SQLite StatementExecutor + using TRowWeakPtr = std::weak_ptr; /// Type to store columns names and indexes using TColumnsMap = std::map>; - RowExecutor(const RowExecutor&) = delete; - RowExecutor(RowExecutor&&) = default; - RowExecutor& operator=(const RowExecutor&) = delete; - RowExecutor& operator=(RowExecutor&&) = default; + StatementExecutor(const StatementExecutor&) = delete; + StatementExecutor(StatementExecutor&&) = default; + StatementExecutor& operator=(const StatementExecutor&) = delete; + StatementExecutor& operator=(StatementExecutor&&) = default; /// Reset the statement to make it ready for a new execution. Throws an exception on error. void reset(); @@ -168,7 +168,7 @@ class RowExecutor /** * @brief InputIterator for statement steps. * - * Remember that this iterator is changing state of RowExecutor. + * Remember that this iterator is changing state of StatementExecutor. */ class RowIterator { @@ -217,7 +217,7 @@ class RowExecutor void advance() noexcept; TStatementWeakPtr mpStatement{}; //!< Weak pointer to SQLite Statement Object - TRowWeakPtr mpRow{}; //!< Weak pointer to RowExecutor Object + TRowWeakPtr mpRow{}; //!< Weak pointer to StatementExecutor Object uint16_t mID{}; //!< Current row number /// Internal row object storage @@ -247,9 +247,9 @@ class RowExecutor * @param[in] apSQLite the SQLite Database Connection * @param[in] aQuery an UTF-8 encoded query string * - * @throws Exception is thrown in case of error, then the RowExecutor object is NOT constructed. + * @throws Exception is thrown in case of error, then the StatementExecutor object is NOT constructed. */ - explicit RowExecutor(sqlite3* apSQLite, const std::string& aQuery); + explicit StatementExecutor(sqlite3* apSQLite, const std::string& aQuery); /** * @brief Return a std::shared_ptr with SQLite Statement Object. diff --git a/src/Column.cpp b/src/Column.cpp index de977ab0..cd1e1bf1 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -26,7 +26,7 @@ const int Null = SQLITE_NULL; // Encapsulation of a Column in a row of the result pointed by the prepared Statement. -Column::Column(const RowExecutor::TStatementPtr& aStmtPtr, int aIndex) : +Column::Column(const StatementExecutor::TStatementPtr& aStmtPtr, int aIndex) : mStmtPtr(aStmtPtr), mIndex(aIndex) { diff --git a/src/Statement.cpp b/src/Statement.cpp index e9101f1e..b12618ff 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -22,7 +22,7 @@ namespace SQLite Statement::Statement(const Database& aDatabase, const std::string& aQuery) : - RowExecutor(aDatabase.getHandle(), aQuery), mQuery(aQuery) + StatementExecutor(aDatabase.getHandle(), aQuery), mQuery(aQuery) {} // Clears away all the bindings of a prepared statement (can be associated with #reset() above). diff --git a/src/RowExecutor.cpp b/src/StatementExecutor.cpp similarity index 79% rename from src/RowExecutor.cpp rename to src/StatementExecutor.cpp index a3eec44a..e4c793f9 100644 --- a/src/RowExecutor.cpp +++ b/src/StatementExecutor.cpp @@ -1,5 +1,5 @@ /** - * @file RowExecutor.cpp + * @file StatementExecutor.cpp * @ingroup SQLiteCpp * @brief Step executor for SQLite prepared Statement Object * @@ -9,7 +9,7 @@ * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) */ -#include +#include #include @@ -19,18 +19,18 @@ namespace SQLite { - RowExecutor::RowExecutor(sqlite3* apSQLite, const std::string& aQuery) + StatementExecutor::StatementExecutor(sqlite3* apSQLite, const std::string& aQuery) : mpSQLite(apSQLite) { prepareStatement(aQuery); createColumnInfo(); - mpRowExecutor.swap(TRowPtr(this, [](const RowExecutor* const) { + mpRowExecutor.swap(TRowPtr(this, [](const StatementExecutor* const) { // empty destructor to make shared_ptr without ownership })); } - void SQLite::RowExecutor::prepareStatement(const std::string& aQuery) + void SQLite::StatementExecutor::prepareStatement(const std::string& aQuery) { if (!mpSQLite) throw SQLite::Exception("Can't create statement without valid database connection"); @@ -49,7 +49,7 @@ namespace SQLite }); } - void SQLite::RowExecutor::createColumnInfo() + void SQLite::StatementExecutor::createColumnInfo() { mColumnCount = sqlite3_column_count(mpStatement.get()); @@ -66,13 +66,13 @@ namespace SQLite } // Reset the statement to make it ready for a new execution (see also #clearBindings() bellow) - void RowExecutor::reset() + void StatementExecutor::reset() { const int ret = tryReset(); check(ret); } - int RowExecutor::tryReset() noexcept + int StatementExecutor::tryReset() noexcept { mbHasRow = false; mbDone = false; @@ -80,7 +80,7 @@ namespace SQLite } // Execute a step of the query to fetch one row of results - bool RowExecutor::executeStep() + bool StatementExecutor::executeStep() { const int ret = tryExecuteStep(); if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem @@ -99,7 +99,7 @@ namespace SQLite } // Execute a one-step query with no expected result, and return the number of changes. - int RowExecutor::exec() + int StatementExecutor::exec() { const int ret = tryExecuteStep(); if (SQLITE_DONE != ret) // the statement has finished executing successfully @@ -122,7 +122,7 @@ namespace SQLite return sqlite3_changes(mpSQLite); } - int RowExecutor::tryExecuteStep() noexcept + int StatementExecutor::tryExecuteStep() noexcept { if (mbDone) { @@ -143,31 +143,31 @@ namespace SQLite } // Get number of rows modified by last INSERT, UPDATE or DELETE statement (not DROP table). - int RowExecutor::getChanges() const noexcept + int StatementExecutor::getChanges() const noexcept { return sqlite3_changes(mpSQLite); } // Return the numeric result code for the most recent failed API call (if any). - int RowExecutor::getErrorCode() const noexcept + int StatementExecutor::getErrorCode() const noexcept { return sqlite3_errcode(mpSQLite); } // Return the extended numeric result code for the most recent failed API call (if any). - int RowExecutor::getExtendedErrorCode() const noexcept + int StatementExecutor::getExtendedErrorCode() const noexcept { return sqlite3_extended_errcode(mpSQLite); } // Return UTF-8 encoded English language explanation of the most recent failed API call (if any). - const char* RowExecutor::getErrorMsg() const noexcept + const char* StatementExecutor::getErrorMsg() const noexcept { return sqlite3_errmsg(mpSQLite); } // Return prepered SQLite statement object or throw - sqlite3_stmt* RowExecutor::getPreparedStatement() const + sqlite3_stmt* StatementExecutor::getPreparedStatement() const { sqlite3_stmt* ret = mpStatement.get(); if (ret) @@ -177,19 +177,19 @@ namespace SQLite throw SQLite::Exception("Statement was not prepared."); } - RowExecutor::RowIterator RowExecutor::begin() + StatementExecutor::RowIterator StatementExecutor::begin() { reset(); tryExecuteStep(); - return RowExecutor::RowIterator(getStatement(), getExecutorWeakPtr(), 0); + return StatementExecutor::RowIterator(getStatement(), getExecutorWeakPtr(), 0); } - RowExecutor::RowIterator RowExecutor::end() + StatementExecutor::RowIterator StatementExecutor::end() { - return RowExecutor::RowIterator(); + return StatementExecutor::RowIterator(); } - void RowExecutor::RowIterator::advance() noexcept + void StatementExecutor::RowIterator::advance() noexcept { if (mpRow.expired()) return; @@ -204,7 +204,7 @@ namespace SQLite } } - bool RowExecutor::RowIterator::operator==(const RowIterator& aIt) const + bool StatementExecutor::RowIterator::operator==(const RowIterator& aIt) const { auto left = mpRow.lock(); auto right = aIt.mpRow.lock();