ThinSQLite++
A thin, safe and convenient modern C++ wrapper for 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/main/LICENSE
7*/
8
9#ifndef HEADER_SQLITEPP_VACKUP_IFACE_INCLUDED
10#define HEADER_SQLITEPP_VACKUP_IFACE_INCLUDED
11
12#include "handle.hpp"
13#include "database_iface.hpp"
14#include "exception_iface.hpp"
15
16namespace thinsqlitepp
17{
32 class backup final : public handle<sqlite3_backup, backup>
33 {
34 public:
40 static std::unique_ptr<backup> init(database & dst, const string_param & dest_dbname,
41 database & src, const string_param & src_dbname)
42 {
44 sqlite3_backup_init(dst.c_ptr(), dest_dbname.c_str(), src.c_ptr(), src_dbname.c_str())));
45 if (!ret)
46 throw exception(sqlite3_errcode(dst.c_ptr()), dst);
47 return ret;
48 }
49
51 ~backup() noexcept
53
54
63
69 step_result step(int page_count)
70 {
71 int ret = sqlite3_backup_step(c_ptr(), page_count);
72 switch(ret)
73 {
74 case SQLITE_BUSY: return busy;
75 case SQLITE_LOCKED: return locked;
76 case SQLITE_DONE: return done;
77 case SQLITE_OK: return success;
78 }
79 throw exception(ret);
80 }
81
87 int remaining() const noexcept
88 { return sqlite3_backup_remaining(c_ptr()); }
89
90
96 int pagecount() const noexcept
97 { return sqlite3_backup_pagecount(c_ptr()); }
98 };
99
100
102}
103
104
105#endif
sqlite3_backup_finish
sqlite3_backup_init
sqlite3_backup_pagecount
sqlite3_backup_remaining
sqlite3_backup_step
Online backup object.
Definition backup_iface.hpp:33
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:40
int remaining() const noexcept
Returns the number of pages still to be backed up after last step()
Definition backup_iface.hpp:87
int pagecount() const noexcept
Returns the total number of pages in the source database after last step()
Definition backup_iface.hpp:96
step_result
Result of a backup step.
Definition backup_iface.hpp:57
@ locked
Source database is being written, retry later (SQLITE_LOCKED)
Definition backup_iface.hpp:61
@ busy
Database is busy, retry later (SQLITE_BUSY)
Definition backup_iface.hpp:60
@ done
Backup finished (SQLITE_DONE)
Definition backup_iface.hpp:58
@ success
Backup step succeeded (SQLITE_OK)
Definition backup_iface.hpp:59
~backup() noexcept
Equivalent to sqlite3_backup_finish.
Definition backup_iface.hpp:51
step_result step(int page_count)
Copy up to page_count pages between the source and destination databases.
Definition backup_iface.hpp:69
A reference to a null terminated string.
Definition string_param.hpp:37
const T * c_str() const noexcept
Returns the stored pointer.
Definition string_param.hpp:50
Database Connection.
Definition database_iface.hpp:108
Exception used to report any SQLite errors.
Definition exception_iface.hpp:166
Base functionality for all fake wrapper classes
Definition handle.hpp:27
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
ThinSQLite++ namespace.
Definition backup_iface.hpp:17
#define SQLITE_BUSY
#define SQLITE_DONE
#define SQLITE_LOCKED
#define SQLITE_OK