Fix compilation of new enum Database::BackupType for C++98

This commit is contained in:
Sébastien Rombauts 2019-07-09 09:29:34 +02:00
parent 514d7d6846
commit c1ab7075f4
4 changed files with 11 additions and 6 deletions

View File

@ -137,3 +137,4 @@ Version ?
- #197 Add tuple_bind and execute_many - #197 Add tuple_bind and execute_many
- #199 Fix #156 misleading error message in exception from Statement::exec - #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 - #201 Add Statement::getExpandedSQL() to get the SQL text of prepared statement with bound parameters expanded
- #211 Implement Database::backup()

View File

@ -434,6 +434,11 @@ public:
*/ */
static bool isUnencrypted(const std::string& aFilename); static bool isUnencrypted(const std::string& aFilename);
/**
* @brief BackupType for the backup() method
*/
enum BackupType { Save, Load };
/** /**
* @brief Load or save the database content. * @brief Load or save the database content.
* *
@ -443,7 +448,6 @@ public:
* *
* @return SQLITE_OK on success or an error code from SQLite. * @return SQLITE_OK on success or an error code from SQLite.
*/ */
enum class BackupType { Save, Load };
int backup(const char* zFilename, BackupType type); int backup(const char* zFilename, BackupType type);
private: private:

View File

@ -314,8 +314,8 @@ int Database::backup(const char* zFilename, BackupType type) {
** Otherwise, if this is a 'save' operation (isSave==1), then data ** Otherwise, if this is a 'save' operation (isSave==1), then data
** is copied from mpSQLite to pFile. Set the variables pFrom and ** is copied from mpSQLite to pFile. Set the variables pFrom and
** pTo accordingly. */ ** pTo accordingly. */
sqlite3* pFrom = (type == BackupType::Save ? mpSQLite : pFile); sqlite3* pFrom = (type == Save ? mpSQLite : pFile);
sqlite3* pTo = (type == BackupType::Save ? pFile : mpSQLite); sqlite3* pTo = (type == Save ? pFile : mpSQLite);
/* Set up the backup procedure to copy from the "main" database of /* Set up the backup procedure to copy from the "main" database of
** connection pFile to the main database of connection mpSQLite. ** connection pFile to the main database of connection mpSQLite.

View File

@ -140,14 +140,14 @@ TEST(Database, import_export)
// Export the data into a file // Export the data into a file
remove("backup"); 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 // Trash the table
db.exec("DROP TABLE test;"); db.exec("DROP TABLE test;");
EXPECT_FALSE(db.tableExists("test")); EXPECT_FALSE(db.tableExists("test"));
// Import the data back from the file // 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")); EXPECT_TRUE(db.tableExists("test"));
} }