From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001 From: John Turner Date: Sun, 14 Sep 2025 00:16:10 -0400 Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35 git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c --- src/backup.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/backup.cpp (limited to 'src/backup.cpp') diff --git a/src/backup.cpp b/src/backup.cpp new file mode 100644 index 0000000..76099b1 --- /dev/null +++ b/src/backup.cpp @@ -0,0 +1,61 @@ +// +// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + + +#include +#include + +BOOST_SQLITE_BEGIN_NAMESPACE + + +void +backup(connection & source, + connection & target, + cstring_ref source_name, + cstring_ref target_name, + system::error_code & ec, + error_info & ei) +{ + struct del + { + void operator()(sqlite3_backup * bp) + { + sqlite3_backup_finish(bp); + } + }; + + std::unique_ptr bu{ + sqlite3_backup_init(target.handle(), target_name.c_str(), + source.handle(), source_name.c_str())}; + if (bu == nullptr) + { + BOOST_SQLITE_ASSIGN_EC(ec, sqlite3_errcode(target.handle())); + ei.set_message(sqlite3_errmsg(target.handle())); + return ; + } + + const auto res = sqlite3_backup_step(bu.get(), -1); + if (SQLITE_DONE != res) + BOOST_SQLITE_ASSIGN_EC(ec, res); +} + + +void +backup(connection & source, + connection & target, + cstring_ref source_name, + cstring_ref target_name) +{ + system::error_code ec; + error_info ei; + backup(source, target, source_name, target_name, ec, ei); + if (ec) + throw_exception(system::system_error(ec, ei.message())); +} + +BOOST_SQLITE_END_NAMESPACE + -- cgit v1.2.3