diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index ac940cb..ea6f71f 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -96,6 +96,9 @@ public: Backup(const Backup&) = delete; Backup& operator=(const Backup&) = delete; + /// Release the SQLite Backup resource. + ~Backup(); + /** * @brief Execute a step of backup with a given number of source pages to be copied * @@ -118,13 +121,7 @@ public: int getTotalPageCount() const; private: - // Deleter functor to use with smart pointers to close the SQLite database backup in an RAII fashion. - struct Deleter - { - void operator()(sqlite3_backup* apBackup); - }; - - std::unique_ptr mpSQLiteBackup{}; ///< Pointer to SQLite Database Backup Handle + sqlite3_backup* mpSQLiteBackup = nullptr; ///< Pointer to SQLite Database Backup Handle }; } // namespace SQLite diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index bc349f9..2dee76d 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -56,10 +56,6 @@ public: */ explicit Column(const Statement::TStatementPtr& aStmtPtr, int aIndex); - // default destructor: the finalization will be done by the destructor of the last shared pointer - // default copy constructor and assignment operator are perfectly suited : - // they copy the Statement::Ptr which in turn increments the reference counter. - /** * @brief Return a pointer to the named assigned to this result column (potentially aliased) * diff --git a/include/SQLiteCpp/Row.h b/include/SQLiteCpp/Row.h new file mode 100644 index 0000000..8a20a6c --- /dev/null +++ b/include/SQLiteCpp/Row.h @@ -0,0 +1,47 @@ +/** + * @file Row.h + * @ingroup SQLiteCpp + * @brief TODO: + * + * Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com) + * Copyright (c) 2015-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt + * or copy at http://opensource.org/licenses/MIT) + */ +#pragma once + +#include + +#include + +// Forward declaration to avoid inclusion of in a header +struct sqlite3_stmt; +class Row; + +namespace SQLite +{ + + +class Row +{ +public: + Row(RowExecutor::TRowPtr apRow, std::size_t aID); + + /** + * @brief Test if the column value is NULL + * + * @param[in] aIndex Index of the column, starting at 0 + * + * @return true if the column value is NULL + * + * Throw an exception if the specified index is out of the [0, getColumnCount()) range. + */ + bool isColumnNull(const int aIndex) const; + +private: + RowExecutor::TRowWeakPtr mpRow; + std::size_t ID; +}; + +} // namespace SQLite diff --git a/include/SQLiteCpp/Savepoint.h b/include/SQLiteCpp/Savepoint.h index 14b25cc..681cde0 100644 --- a/include/SQLiteCpp/Savepoint.h +++ b/include/SQLiteCpp/Savepoint.h @@ -90,6 +90,6 @@ class Savepoint { private: Database& mDatabase; ///< Reference to the SQLite Database Connection std::string msName; ///< Name of the Savepoint - bool mbReleased{ false }; ///< True when release has been called + bool mbReleased = false; ///< True when release has been called }; } // namespace SQLite diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 4982352..ce95893 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -698,12 +698,12 @@ private: std::string mQuery; //!< UTF-8 SQL Query sqlite3* mpSQLite; //!< Pointer to SQLite Database Connection Handle TStatementPtr mpPreparedStatement; //!< Shared Pointer to the prepared SQLite Statement Object - int mColumnCount{0}; //!< Number of columns in the result of the prepared statement - bool mbHasRow{false}; //!< true when a row has been fetched with executeStep() - bool mbDone{false}; //!< true when the last executeStep() had no more row to fetch + int mColumnCount = 0; //!< Number of columns in the result of the prepared statement + bool mbHasRow = false; //!< true when a row has been fetched with executeStep() + bool mbDone = false; //!< true when the last executeStep() had no more row to fetch /// Map of columns index by name (mutable so getColumnIndex can be const) - mutable std::map> mColumnNames{}; + mutable std::map> mColumnNames; }; diff --git a/include/SQLiteCpp/Transaction.h b/include/SQLiteCpp/Transaction.h index 0fdefea..a2198f9 100644 --- a/include/SQLiteCpp/Transaction.h +++ b/include/SQLiteCpp/Transaction.h @@ -88,7 +88,7 @@ public: private: Database& mDatabase; ///< Reference to the SQLite Database Connection - bool mbCommited{ false }; ///< True when commit has been called + bool mbCommited = false; ///< True when commit has been called }; diff --git a/src/Backup.cpp b/src/Backup.cpp index 92920d8..4c91e69 100644 --- a/src/Backup.cpp +++ b/src/Backup.cpp @@ -24,10 +24,10 @@ Backup::Backup(Database& aDestDatabase, Database& aSrcDatabase, const char* apSrcDatabaseName) { - mpSQLiteBackup.reset(sqlite3_backup_init(aDestDatabase.getHandle(), + mpSQLiteBackup = sqlite3_backup_init(aDestDatabase.getHandle(), apDestDatabaseName, aSrcDatabase.getHandle(), - apSrcDatabaseName)); + apSrcDatabaseName); if (nullptr == mpSQLiteBackup) { // If an error occurs, the error code and message are attached to the destination database connection. @@ -48,10 +48,19 @@ Backup::Backup(Database &aDestDatabase, Database &aSrcDatabase) : { } +// Release resource for SQLite database backup +Backup::~Backup() +{ + if (mpSQLiteBackup) + { + sqlite3_backup_finish(mpSQLiteBackup); + } +} + // Execute backup step with a given number of source pages to be copied int Backup::executeStep(const int aNumPage /* = -1 */) { - const int res = sqlite3_backup_step(mpSQLiteBackup.get(), aNumPage); + const int res = sqlite3_backup_step(mpSQLiteBackup, aNumPage); if (SQLITE_OK != res && SQLITE_DONE != res && SQLITE_BUSY != res && SQLITE_LOCKED != res) { throw SQLite::Exception(sqlite3_errstr(res), res); @@ -62,22 +71,14 @@ int Backup::executeStep(const int aNumPage /* = -1 */) // Get the number of remaining source pages to be copied in this backup process int Backup::getRemainingPageCount() const { - return sqlite3_backup_remaining(mpSQLiteBackup.get()); + return sqlite3_backup_remaining(mpSQLiteBackup); } // Get the number of total source pages to be copied in this backup process int Backup::getTotalPageCount() const { - return sqlite3_backup_pagecount(mpSQLiteBackup.get()); + return sqlite3_backup_pagecount(mpSQLiteBackup); } -// Release resource for SQLite database backup -void SQLite::Backup::Deleter::operator()(sqlite3_backup* apBackup) -{ - if (apBackup) - { - sqlite3_backup_finish(apBackup); - } -} } // namespace SQLite diff --git a/src/Row.cpp b/src/Row.cpp new file mode 100644 index 0000000..0ddc0d1 --- /dev/null +++ b/src/Row.cpp @@ -0,0 +1,25 @@ +/** + * @file Row.cpp + * @ingroup SQLiteCpp + * @brief TODO: + * + * Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com) + * Copyright (c) 2015-2021 Sebastien Rombauts (sebastien.rombauts@gmail.com) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt + * or copy at http://opensource.org/licenses/MIT) + */ +#include + +#include + +#include + +namespace SQLite +{ + + + ; + + +} // namespace SQLite