Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/sqlite.cpp
Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | void SQLiteDatabase::Open() { | ||||
} | } | ||||
} | } | ||||
bool SQLiteDatabase::Rewrite(const char *skip) { | bool SQLiteDatabase::Rewrite(const char *skip) { | ||||
return false; | return false; | ||||
} | } | ||||
bool SQLiteDatabase::Backup(const std::string &dest) const { | bool SQLiteDatabase::Backup(const std::string &dest) const { | ||||
sqlite3 *db_copy; | |||||
int res = sqlite3_open(dest.c_str(), &db_copy); | |||||
if (res != SQLITE_OK) { | |||||
sqlite3_close(db_copy); | |||||
return false; | |||||
} | |||||
sqlite3_backup *backup = sqlite3_backup_init(db_copy, "main", m_db, "main"); | |||||
if (!backup) { | |||||
LogPrintf("%s: Unable to begin backup: %s\n", __func__, | |||||
sqlite3_errmsg(m_db)); | |||||
sqlite3_close(db_copy); | |||||
return false; | return false; | ||||
} | } | ||||
// Specifying -1 will copy all of the pages | |||||
res = sqlite3_backup_step(backup, -1); | |||||
if (res != SQLITE_DONE) { | |||||
LogPrintf("%s: Unable to backup: %s\n", __func__, sqlite3_errstr(res)); | |||||
sqlite3_backup_finish(backup); | |||||
sqlite3_close(db_copy); | |||||
return false; | |||||
} | |||||
res = sqlite3_backup_finish(backup); | |||||
sqlite3_close(db_copy); | |||||
return res == SQLITE_OK; | |||||
} | |||||
void SQLiteDatabase::Close() { | void SQLiteDatabase::Close() { | ||||
int res = sqlite3_close(m_db); | int res = sqlite3_close(m_db); | ||||
if (res != SQLITE_OK) { | if (res != SQLITE_OK) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("SQLiteDatabase: Failed to close database: %s\n", | strprintf("SQLiteDatabase: Failed to close database: %s\n", | ||||
sqlite3_errstr(res))); | sqlite3_errstr(res))); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines |