ThinSQLite++
A thin, safe and convenient modern C++ wrapper for the SQLite API.
Loading...
Searching...
No Matches
backup_iface.hpp
1/*
2 Copyright 2024 Eugene Gershnik
3
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://github.com/gershnik/thinsqlitepp/blob/master/LICENSE
7*/
8
9#ifndef HEADER_SQLITEPP_BACKUP_IFACE_INCLUDED
10#define HEADER_SQLITEPP_BACKUP_IFACE_INCLUDED
11
12#include "handle.hpp"
13#include "database_iface.hpp"
14#include "exception_iface.hpp"
15
16namespace thinsqlitepp
17{
22
32 SQLITEPP_EXPORTED
33 class backup final : public handle<sqlite3_backup, backup>
34 {
35 public:
41 static std::unique_ptr<backup> init(database & dst, const string_param & dest_dbname,
42 database & src, const string_param & src_dbname)
43 {
45 sqlite3_backup_init(dst.c_ptr(), dest_dbname.c_str(), src.c_ptr(), src_dbname.c_str())));
46 if (!ret)
47 throw exception(sqlite3_errcode(dst.c_ptr()), dst);
48 return ret;
49 }
50
52 ~backup() noexcept
54
55
64
70 step_result step(int page_count)
71 {
72 int ret = sqlite3_backup_step(c_ptr(), page_count);
73 switch(ret)
74 {
75 case SQLITE_BUSY: return busy;
76 case SQLITE_LOCKED: return locked;
77 case SQLITE_DONE: return done;
78 case SQLITE_OK: return success;
79 }
80 throw exception(ret);
81 }
82
88 int remaining() const noexcept
89 { return sqlite3_backup_remaining(c_ptr()); }
90
91
97 int pagecount() const noexcept
98 { return sqlite3_backup_pagecount(c_ptr()); }
99 };
100
101
103}
104
105
106#endif
sqlite3_backup_finish
sqlite3_backup_init
sqlite3_backup_pagecount
sqlite3_backup_remaining
sqlite3_backup_step
Online backup object.
Definition backup_iface.hpp:34
static std::unique_ptr< backup > init(database &dst, const string_param &dest_dbname, database &src, const string_param &src_dbname)
Initialize the backup.
Definition backup_iface.hpp:41
int remaining() const noexcept
Returns the number of pages still to be backed up after last step().
Definition backup_iface.hpp:88
int pagecount() const noexcept
Returns the total number of pages in the source database after last step().
Definition backup_iface.hpp:97
step_result
Result of a backup step.
Definition backup_iface.hpp:58
@ locked
Source database is being written, retry later (SQLITE_LOCKED).
Definition backup_iface.hpp:62
@ busy
Database is busy, retry later (SQLITE_BUSY).
Definition backup_iface.hpp:61
@ done
Backup finished (SQLITE_DONE).
Definition backup_iface.hpp:59
@ success
Backup step succeeded (SQLITE_OK).
Definition backup_iface.hpp:60
~backup() noexcept
Equivalent to sqlite3_backup_finish.
Definition backup_iface.hpp:52
step_result step(int page_count)
Copy up to page_count pages between the source and destination databases.
Definition backup_iface.hpp:70
const T * c_str() const noexcept
Returns the stored pointer.
Definition string_param.hpp:51
Database Connection.
Definition database_iface.hpp:109
Exception used to report any SQLite errors.
Definition exception_iface.hpp:180
T * c_ptr() const noexcept
Access the real underlying SQLite type.
Definition handle.hpp:45
static backup * from(sqlite3_backup *obj) noexcept
Definition handle.hpp:41
sqlite3_errcode
basic_string_param< char > string_param
Convenience typedef.
Definition string_param.hpp:58
ThinSQLite++ namespace.
Definition backup_iface.hpp:17
#define SQLITE_BUSY
#define SQLITE_DONE
#define SQLITE_LOCKED
#define SQLITE_OK