diff --git a/include/SQLiteCpp/Backup.h b/include/SQLiteCpp/Backup.h index d4dd5e0..e260d1d 100644 --- a/include/SQLiteCpp/Backup.h +++ b/include/SQLiteCpp/Backup.h @@ -1,7 +1,7 @@ /** * @file Backup.h * @ingroup SQLiteCpp - * @brief Management of a SQLite Database Backup. + * @brief Backup is used to backup a database file in a safe and online way. * * Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com) * @@ -19,6 +19,23 @@ namespace SQLite { +/** + * @brief RAII encapsulation of a SQLite Database Backup process. + * + * A Backup object is used to backup a source database file to a destination database file + * in a safe and online way. + * + * Resource Acquisition Is Initialization (RAII) means that the Backup Resource + * is allocated in the constructor and released in the destructor, so that there is + * no need to worry about memory management or the validity of the underlying SQLite Backup. + * + * Thread-safety: a Backup 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"). + */ class Backup { public: diff --git a/src/Backup.cpp b/src/Backup.cpp index 60f22e6..4f2e414 100644 --- a/src/Backup.cpp +++ b/src/Backup.cpp @@ -1,7 +1,7 @@ /** * @file Backup.cpp * @ingroup SQLiteCpp - * @brief Management of a SQLite Database Backup. + * @brief Backup is used to backup a database file in a safe and online way. * * Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com) * @@ -74,9 +74,16 @@ Backup::~Backup() noexcept } } -int Backup::executeStep(const int aNumPage) +int Backup::executeStep(const int aNumPage /* = -1 */) { const int res = sqlite3_backup_step(mpSQLiteBackup, aNumPage); + if (SQLITE_OK != res && SQLITE_DONE != res && + SQLITE_BUSY != res && SQLITE_LOCKED != res) + { + std::string strerr("Backup executeStep error with message "); + strerr += sqlite3_errstr(res); + throw SQLite::Exception(strerr); + } return res; }