File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,29 @@ bool SQLiteDatabase::Rewrite(const char* skip)
186186
187187bool SQLiteDatabase::Backup (const std::string& dest) const
188188{
189- return false ;
189+ sqlite3* db_copy;
190+ int res = sqlite3_open (dest.c_str (), &db_copy);
191+ if (res != SQLITE_OK) {
192+ sqlite3_close (db_copy);
193+ return false ;
194+ }
195+ sqlite3_backup* backup = sqlite3_backup_init (db_copy, " main" , m_db, " main" );
196+ if (!backup) {
197+ LogPrintf (" %s: Unable to begin backup: %s\n " , __func__, sqlite3_errmsg (m_db));
198+ sqlite3_close (db_copy);
199+ return false ;
200+ }
201+ // Specifying -1 will copy all of the pages
202+ res = sqlite3_backup_step (backup, -1 );
203+ if (res != SQLITE_DONE) {
204+ LogPrintf (" %s: Unable to backup: %s\n " , __func__, sqlite3_errstr (res));
205+ sqlite3_backup_finish (backup);
206+ sqlite3_close (db_copy);
207+ return false ;
208+ }
209+ res = sqlite3_backup_finish (backup);
210+ sqlite3_close (db_copy);
211+ return res == SQLITE_OK;
190212}
191213
192214void SQLiteDatabase::Close ()
You can’t perform that action at this time.
0 commit comments