Skip to content

Commit

Permalink
Rename RowExecutor to StatementExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperos155 committed Jul 25, 2022
1 parent 826a17f commit 4117377
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/SQLiteCpp/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
};

Expand Down
4 changes: 2 additions & 2 deletions include/SQLiteCpp/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
#pragma once

#include <SQLiteCpp/RowExecutor.h>
#include <SQLiteCpp/StatementExecutor.h>
#include <SQLiteCpp/Exception.h>
#include <SQLiteCpp/Utils.h> // SQLITECPP_PURE_FUNC

Expand Down Expand Up @@ -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:
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file RowExecutor.h
* @file StatementExecutor.h
* @ingroup SQLiteCpp
* @brief Step executor for SQLite prepared Statement Object
*
Expand Down Expand Up @@ -33,15 +33,15 @@ 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++,
* because of the way it shares the underling SQLite precompiled statement
* 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
Expand All @@ -50,19 +50,19 @@ class RowExecutor
/// Weak pointer to SQLite Prepared Statement Object
using TStatementWeakPtr = std::weak_ptr<sqlite3_stmt>;

/// Shared pointer to SQLite RowExecutor
using TRowPtr = std::shared_ptr<RowExecutor>;
/// Shared pointer to SQLite StatementExecutor
using TRowPtr = std::shared_ptr<StatementExecutor>;

/// Weak pointer to SQLite RowExecutor
using TRowWeakPtr = std::weak_ptr<RowExecutor>;
/// Weak pointer to SQLite StatementExecutor
using TRowWeakPtr = std::weak_ptr<StatementExecutor>;

/// Type to store columns names and indexes
using TColumnsMap = std::map<std::string, int, std::less<>>;

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();
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
44 changes: 22 additions & 22 deletions src/RowExecutor.cpp → src/StatementExecutor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file RowExecutor.cpp
* @file StatementExecutor.cpp
* @ingroup SQLiteCpp
* @brief Step executor for SQLite prepared Statement Object
*
Expand All @@ -9,7 +9,7 @@
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#include <SQLiteCpp/RowExecutor.h>
#include <SQLiteCpp/StatementExecutor.h>

#include <SQLiteCpp/Exception.h>

Expand All @@ -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");
Expand All @@ -49,7 +49,7 @@ namespace SQLite
});
}

void SQLite::RowExecutor::createColumnInfo()
void SQLite::StatementExecutor::createColumnInfo()
{
mColumnCount = sqlite3_column_count(mpStatement.get());

Expand All @@ -66,21 +66,21 @@ 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;
return sqlite3_reset(mpStatement.get());
}

// 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
Expand All @@ -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
Expand All @@ -122,7 +122,7 @@ namespace SQLite
return sqlite3_changes(mpSQLite);
}

int RowExecutor::tryExecuteStep() noexcept
int StatementExecutor::tryExecuteStep() noexcept
{
if (mbDone)
{
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 4117377

Please sign in to comment.