Renamed Backup accessors and use a forward declaration to sqlite3_backup

This commit is contained in:
Sébastien Rombauts 2016-07-05 07:49:38 +02:00
parent 9fa00ea5ed
commit db7aefb271
3 changed files with 17 additions and 24 deletions

View File

@ -10,12 +10,13 @@
*/ */
#pragma once #pragma once
#include <sqlite3.h>
#include <SQLiteCpp/Database.h> #include <SQLiteCpp/Database.h>
#include <string> #include <string>
// Forward declaration to avoid including the sqlite3.h header
struct sqlite3_backup;
namespace SQLite namespace SQLite
{ {
@ -97,9 +98,7 @@ public:
Backup(Database& aDestDatabase, Backup(Database& aDestDatabase,
Database& aSrcDatabase); Database& aSrcDatabase);
/** /// Release the SQLite Backup resource.
* @brief Release the SQLite Backup resource.
*/
virtual ~Backup() noexcept; virtual ~Backup() noexcept;
/** /**
@ -117,19 +116,11 @@ public:
*/ */
int executeStep(const int aNumPage = -1); int executeStep(const int aNumPage = -1);
/** /// Return the number of source pages still to be backed up as of the most recent call to executeStep().
* @brief Get the remaining number of source pages to be copied. int getRemainingPageCount();
*
* @return the remaining number of source pages to be copied
*/
int remainingPageCount();
/** /// Return the total number of pages in the source database as of the most recent call to executeStep().
* @brief Get the total number of source pages. int getTotalPageCount();
*
* @return the total number of source pages
*/
int totalPageCount();
private: private:
/// @{ Backup must be non-copyable /// @{ Backup must be non-copyable

View File

@ -13,6 +13,8 @@
#include <SQLiteCpp/Exception.h> #include <SQLiteCpp/Exception.h>
#include <sqlite3.h>
#include <string> #include <string>
namespace SQLite namespace SQLite
@ -90,13 +92,13 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
} }
// Get the number of remaining source pages to be copied in this backup process // Get the number of remaining source pages to be copied in this backup process
int Backup::remainingPageCount() int Backup::getRemainingPageCount()
{ {
return sqlite3_backup_remaining(mpSQLiteBackup); return sqlite3_backup_remaining(mpSQLiteBackup);
} }
// Get the number of total source pages to be copied in this backup process // Get the number of total source pages to be copied in this backup process
int Backup::totalPageCount() int Backup::getTotalPageCount()
{ {
return sqlite3_backup_pagecount(mpSQLiteBackup); return sqlite3_backup_pagecount(mpSQLiteBackup);
} }

View File

@ -44,13 +44,13 @@ TEST(Backup, executeStepOne) {
SQLite::Backup backup(destDB, "main", srcDB, "main"); SQLite::Backup backup(destDB, "main", srcDB, "main");
int res = backup.executeStep(1); // backup only one page at a time int res = backup.executeStep(1); // backup only one page at a time
ASSERT_EQ(SQLITE_OK, res); ASSERT_EQ(SQLITE_OK, res);
const int total = backup.totalPageCount(); const int total = backup.getTotalPageCount();
ASSERT_EQ(2, total); ASSERT_EQ(2, total);
int remaining = backup.remainingPageCount(); int remaining = backup.getRemainingPageCount();
ASSERT_EQ(1, remaining); ASSERT_EQ(1, remaining);
res = backup.executeStep(1); // backup the second and last page res = backup.executeStep(1); // backup the second and last page
ASSERT_EQ(SQLITE_DONE, res); ASSERT_EQ(SQLITE_DONE, res);
remaining = backup.remainingPageCount(); remaining = backup.getRemainingPageCount();
ASSERT_EQ(0, remaining); ASSERT_EQ(0, remaining);
SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC"); SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC");
@ -76,9 +76,9 @@ TEST(Backup, executeStepAll) {
SQLite::Backup backup(destDB, srcDB); SQLite::Backup backup(destDB, srcDB);
const int res = backup.executeStep(); // uses default argument "-1" => execute all steps at once const int res = backup.executeStep(); // uses default argument "-1" => execute all steps at once
ASSERT_EQ(res, SQLITE_DONE); ASSERT_EQ(res, SQLITE_DONE);
const int total = backup.totalPageCount(); const int total = backup.getTotalPageCount();
ASSERT_EQ(2, total); ASSERT_EQ(2, total);
const int remaining = backup.remainingPageCount(); const int remaining = backup.getRemainingPageCount();
ASSERT_EQ(0, remaining); ASSERT_EQ(0, remaining);
SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC"); SQLite::Statement query(destDB, "SELECT * FROM backup_test ORDER BY id ASC");