diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c80d81..54c6ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -136,4 +136,5 @@ Version ? - #192 Add wrapper for bind parameter count - #197 Add tuple_bind and execute_many - #199 Fix #156 misleading error message in exception from Statement::exec -- #201 Add Statement::getExpandedSQL() to get the SQL text of prepared statement with bound parameters expanded \ No newline at end of file +- #201 Add Statement::getExpandedSQL() to get the SQL text of prepared statement with bound parameters expanded +- #211 Implement Database::backup() diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 0836511..1584a6e 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -434,6 +434,11 @@ public: */ static bool isUnencrypted(const std::string& aFilename); + /** + * @brief BackupType for the backup() method + */ + enum BackupType { Save, Load }; + /** * @brief Load or save the database content. * @@ -443,7 +448,6 @@ public: * * @return SQLITE_OK on success or an error code from SQLite. */ - enum class BackupType { Save, Load }; int backup(const char* zFilename, BackupType type); private: diff --git a/src/Database.cpp b/src/Database.cpp index 0a10bbd..88a35b1 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -314,8 +314,8 @@ int Database::backup(const char* zFilename, BackupType type) { ** Otherwise, if this is a 'save' operation (isSave==1), then data ** is copied from mpSQLite to pFile. Set the variables pFrom and ** pTo accordingly. */ - sqlite3* pFrom = (type == BackupType::Save ? mpSQLite : pFile); - sqlite3* pTo = (type == BackupType::Save ? pFile : mpSQLite); + sqlite3* pFrom = (type == Save ? mpSQLite : pFile); + sqlite3* pTo = (type == Save ? pFile : mpSQLite); /* Set up the backup procedure to copy from the "main" database of ** connection pFile to the main database of connection mpSQLite. diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp index 030b653..b9973e3 100644 --- a/tests/Database_test.cpp +++ b/tests/Database_test.cpp @@ -140,14 +140,14 @@ TEST(Database, import_export) // Export the data into a file remove("backup"); - EXPECT_EQ(db.backup("backup", SQLite::Database::BackupType::Save), SQLITE_OK); + EXPECT_EQ(db.backup("backup", SQLite::Database::Save), SQLITE_OK); // Trash the table db.exec("DROP TABLE test;"); EXPECT_FALSE(db.tableExists("test")); // Import the data back from the file - EXPECT_EQ(db.backup("backup", SQLite::Database::BackupType::Load), SQLITE_OK); + EXPECT_EQ(db.backup("backup", SQLite::Database::Load), SQLITE_OK); EXPECT_TRUE(db.tableExists("test")); }