VSQLite++ 0.3
Loading...
Searching...
No Matches
snapshot.hpp
Go to the documentation of this file.
1/*##############################################################################
2 VSQLite++ - virtuosic bytes SQLite3 C++ wrapper
3
4 Copyright (c) 2006-2024 Vinzenz Feenstra
5 and contributors
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10
11 * Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16 * Neither the name of virtuosic bytes nor the names of its contributors may
17 be used to endorse or promote products derived from this software without
18 specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32##############################################################################*/
33#ifndef GUARD_SQLITE_SNAPSHOT_HPP_INCLUDED
34#define GUARD_SQLITE_SNAPSHOT_HPP_INCLUDED
35
36#include <string>
37#include <string_view>
38
39struct sqlite3_snapshot;
40
48namespace sqlite {
49inline namespace v2 {
50 struct connection;
51
60
62 struct snapshot {
63 snapshot() = default;
65
66 snapshot(snapshot const &) = delete;
67 snapshot &operator=(snapshot const &) = delete;
68
69 snapshot(snapshot &&other) noexcept;
70 snapshot &operator=(snapshot &&other) noexcept;
71
72 bool valid() const noexcept {
73 return handle_ != nullptr;
74 }
75 explicit operator bool() const noexcept {
76 return valid();
77 }
78
80 void reset() noexcept;
81
83 static snapshot take(connection &con, std::string_view schema = "main");
84
86 void open(connection &con, std::string_view schema = "main") const;
87
88 sqlite3_snapshot *native_handle() const noexcept {
89 return handle_;
90 }
91
92 private:
93 explicit snapshot(sqlite3_snapshot *handle);
94 sqlite3_snapshot *handle_ = nullptr;
95 };
96
99
101 wal_mode enable_wal(connection &con, bool prefer_wal2 = false);
102
105
107 std::string_view to_string(wal_mode mode);
108
110 bool snapshots_supported() noexcept;
111} // namespace v2
112} // namespace sqlite
113
114#endif // GUARD_SQLITE_SNAPSHOT_HPP_INCLUDED
wal_mode set_wal_mode(connection &con, wal_mode mode)
Force a specific WAL journal mode.
wal_mode get_wal_mode(connection &con)
Query the current journal mode for a connection.
std::string_view to_string(wal_mode mode)
Convert wal_mode to the corresponding PRAGMA token.
wal_mode enable_wal(connection &con, bool prefer_wal2=false)
Enable WAL, optionally preferring WAL2 with transparent fallback.
bool snapshots_supported() noexcept
Check if the linked SQLite library exposes snapshot helpers.
@ rollback
DELETE/legacy rollback journal.
Definition snapshot.hpp:53
connection is used to open, close, attach and detach a database. Further it has to be passed to all c...
RAII wrapper around sqlite3_snapshot.
Definition snapshot.hpp:62
sqlite3_snapshot * handle_
Definition snapshot.hpp:94
snapshot & operator=(snapshot const &)=delete
snapshot(snapshot const &)=delete
snapshot(sqlite3_snapshot *handle)
snapshot(snapshot &&other) noexcept
sqlite3_snapshot * native_handle() const noexcept
Definition snapshot.hpp:88
static snapshot take(connection &con, std::string_view schema="main")
Capture a snapshot for the provided connection/schema.
snapshot & operator=(snapshot &&other) noexcept
void open(connection &con, std::string_view schema="main") const
Rewind an open read transaction to this snapshot.
bool valid() const noexcept
Definition snapshot.hpp:72
void reset() noexcept
Release the managed sqlite3_snapshot (if owned).