From 2800b65ac6ac06607befce1074e5ff14303d5ab0 Mon Sep 17 00:00:00 2001 From: Kacperos155 <56676161+Kacperos155@users.noreply.github.com> Date: Tue, 25 Jan 2022 20:32:40 +0100 Subject: [PATCH] Set Statement move constractor to default; fix #347 --- include/SQLiteCpp/Column.h | 4 ++-- include/SQLiteCpp/Statement.h | 3 ++- src/Statement.cpp | 16 +--------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 13437c4..069c6f5 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -54,7 +54,7 @@ public: * @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object. * @param[in] aIndex Index of the column in the row of result, starting at 0 */ - Column(Statement::TStatementPtr& aStmtPtr, int aIndex) noexcept; + explicit Column(Statement::TStatementPtr& aStmtPtr, int aIndex) noexcept; // default destructor: the finalization will be done by the destructor of the last shared pointer // default copy constructor and assignment operator are perfectly suited : @@ -246,7 +246,7 @@ public: * * @see getString */ - operator std::string() const + explicit operator std::string() const { return getString(); } diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index f8bcd9f..8610fdd 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -79,7 +79,8 @@ public: * * @param[in] aStatement Statement to move */ - Statement(Statement&& aStatement) noexcept; + Statement(Statement&& aStatement) noexcept = default; + Statement& operator=(Statement&& aStatement) noexcept = default; // Statement is non-copyable Statement(const Statement&) = delete; diff --git a/src/Statement.cpp b/src/Statement.cpp index 2a2749b..29ea133 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -28,20 +28,6 @@ Statement::Statement(Database &aDatabase, const char* apQuery) : mColumnCount = sqlite3_column_count(mpPreparedStatement.get()); } -Statement::Statement(Statement&& aStatement) noexcept : - mQuery(std::move(aStatement.mQuery)), - mpSQLite(aStatement.mpSQLite), - mpPreparedStatement(std::move(aStatement.mpPreparedStatement)), - mColumnCount(aStatement.mColumnCount), - mbHasRow(aStatement.mbHasRow), - mbDone(aStatement.mbDone) -{ - aStatement.mpSQLite = nullptr; - aStatement.mColumnCount = 0; - aStatement.mbHasRow = false; - aStatement.mbDone = false; -} - // Reset the statement to make it ready for a new execution (see also #clearBindings() bellow) void Statement::reset() { @@ -342,7 +328,7 @@ std::string Statement::getExpandedSQL() { Statement::TStatementPtr Statement::prepareStatement() { sqlite3_stmt* statement; - const int ret = sqlite3_prepare_v2(mpSQLite, mQuery.c_str(), static_cast(mQuery.size()), &statement, NULL); + const int ret = sqlite3_prepare_v2(mpSQLite, mQuery.c_str(), static_cast(mQuery.size()), &statement, nullptr); if (SQLITE_OK != ret) { throw SQLite::Exception(mpSQLite, ret);