1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 <boost/sqlite/backup.hpp>
#include <boost/sqlite/connection.hpp>
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<sqlite3_backup, del> 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
|