/*** @file Backup.cpp* @ingroup SQLiteCpp* @brief Backup is used to backup a database file in a safe and online way.** Copyright (c) 2015 Shibao HONG (shibaohong@outlook.com)* Copyright (c) 2015-2025 Sebastien Rombauts (sebastien.rombauts@gmail.com)** Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt* or copy at http://opensource.org/licenses/MIT)*/#include <SQLiteCpp/Backup.h>#include <SQLiteCpp/Exception.h>#include <sqlite3.h>namespace SQLite{// Initialize resource for SQLite database backupBackup::Backup(Database& aDestDatabase,const char* apDestDatabaseName,Database& aSrcDatabase,const char* apSrcDatabaseName){mpSQLiteBackup.reset(sqlite3_backup_init(aDestDatabase.getHandle(),apDestDatabaseName,aSrcDatabase.getHandle(),apSrcDatabaseName));if (nullptr == mpSQLiteBackup){// If an error occurs, the error code and message are attached to the destination database connection.throw SQLite::Exception(aDestDatabase.getHandle());}}Backup::Backup(Database& aDestDatabase,const std::string& aDestDatabaseName,Database& aSrcDatabase,const std::string& aSrcDatabaseName) :Backup(aDestDatabase, aDestDatabaseName.c_str(), aSrcDatabase, aSrcDatabaseName.c_str()){}Backup::Backup(Database &aDestDatabase, Database &aSrcDatabase) :Backup(aDestDatabase, "main", aSrcDatabase, "main"){}// Execute backup step with a given number of source pages to be copiedint Backup::executeStep(const int aNumPage /* = -1 */){const int res = sqlite3_backup_step(mpSQLiteBackup.get(), aNumPage);if (SQLITE_OK != res && SQLITE_DONE != res && SQLITE_BUSY != res && SQLITE_LOCKED != res){throw SQLite::Exception(sqlite3_errstr(res), res);}return res;}// Get the number of remaining source pages to be copied in this backup processint Backup::getRemainingPageCount() const{return sqlite3_backup_remaining(mpSQLiteBackup.get());}// Get the number of total source pages to be copied in this backup processint Backup::getTotalPageCount() const{return sqlite3_backup_pagecount(mpSQLiteBackup.get());}// Release resource for SQLite database backupvoid SQLite::Backup::Deleter::operator()(sqlite3_backup* apBackup){if (apBackup){sqlite3_backup_finish(apBackup);}}} // namespace SQLite
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。