ThinSQLite++
A thin, safe and convenient modern C++ wrapper for SQLite API.
Loading...
Searching...
No Matches
global_iface.hpp
1/*
2 Copyright 2019 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_GLOBAL_IFACE_INCLUDED
10#define HEADER_SQLITEPP_GLOBAL_IFACE_INCLUDED
11
12#include "exception_iface.hpp"
13
14#include <cstdint>
15
19namespace thinsqlitepp
20{
33 inline void initialize()
34 {
35 int res = sqlite3_initialize();
36 if (res != SQLITE_OK)
37 throw exception(res);
38 }
39
47 inline void shutdown() noexcept
48 {
50 }
51
54 namespace internal
55 {
56 template<int Code, class ...Args>
57 struct config_option
58 {
59 static void apply(Args && ...args)
60 {
61 int res = sqlite3_config(Code, std::forward<Args>(args)...);
62 if (res != SQLITE_OK)
63 throw exception(res);
64 }
65 };
66
67 template<int Code> struct config_mapping;
68
69 }
70
88 template<int Code, class ...Args>
89 inline
90 auto config(Args && ...args) ->
91 #ifndef DOXYGEN
92 //void but prevents instantiation with wrong types
93 decltype(
94 internal::config_mapping<Code>::type::apply(std::forward<decltype(args)>(args)...)
95 )
96 #else
97 void
98 #endif
99 { internal::config_mapping<Code>::type::apply(std::forward<Args>(args)...); }
100
105 namespace internal
106 {
107 SQLITEPP_SUPPRESS_SILLY_VARARG_WARNING_BEGIN
108
109 #if SQLITEPP_USE_VARARG_POUND_POUND_TRICK
110
111 //Idiotic GCC in pedantic mode warns on MACRO(arg) for MARCO(x,...) in < C++20 mode
112 //with no way to disable the warning(!!!).
113 #define SQLITEPP_DEFINE_OPTION_0(code) \
114 template<> struct config_mapping<code> { using type = config_option<code>; };
115 #define SQLITEPP_DEFINE_OPTION_N(code, ...) \
116 template<> struct config_mapping<code> { using type = config_option<code, ##__VA_ARGS__>; };
117
118 #else
119
120 #define SQLITEPP_DEFINE_OPTION(code, ...) \
121 template<> struct config_mapping<code> { using type = config_option<code __VA_OPT__(,) __VA_ARGS__>; };
122
123 #define SQLITEPP_DEFINE_OPTION_N(code, ...) SQLITEPP_DEFINE_OPTION(code __VA_OPT__(,) __VA_ARGS__)
124 #define SQLITEPP_DEFINE_OPTION_0(code) SQLITEPP_DEFINE_OPTION_N(code)
125
126 #endif
127
128 //@ [Config Options]
129
130 SQLITEPP_DEFINE_OPTION_0( SQLITE_CONFIG_SINGLETHREAD );
131 SQLITEPP_DEFINE_OPTION_0( SQLITE_CONFIG_MULTITHREAD );
132 SQLITEPP_DEFINE_OPTION_0( SQLITE_CONFIG_SERIALIZED );
133 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_MALLOC, sqlite3_mem_methods *);
134 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_GETMALLOC, sqlite3_mem_methods *);
135 #ifdef SQLITE_CONFIG_SMALL_MALLOC
136 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_SMALL_MALLOC, int);
137 #endif
138 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_MEMSTATUS, int);
139 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_PAGECACHE, void *, int, int);
140 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_HEAP, void *, int, int);
141 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_MUTEX, sqlite3_mutex_methods *);
142 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_GETMUTEX, sqlite3_mutex_methods *);
143 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_LOOKASIDE, int, int);
144 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_PCACHE2, sqlite3_pcache_methods2 *);
145 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_GETPCACHE2, sqlite3_pcache_methods2 *);
146 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_LOG, void (*)(void*, int, const char *), void *);
147 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_URI, int);
148 #ifdef SQLITE_CONFIG_COVERING_INDEX_SCAN
149 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_COVERING_INDEX_SCAN, int);
150 #endif
151 #ifdef SQLITE_CONFIG_SQLLOG
152 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_SQLLOG, void (*)(void *, sqlite3 *, const char *, int), void *);
153 #endif
154 #ifdef SQLITE_CONFIG_MMAP_SIZE
155 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_MMAP_SIZE, int64_t, int64_t);
156 #endif
157 #ifdef SQLITE_CONFIG_WIN32_HEAPSIZE
158 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_WIN32_HEAPSIZE, int);
159 #endif
160 #ifdef SQLITE_CONFIG_PCACHE_HDRSZ
161 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_PCACHE_HDRSZ, int *);
162 #endif
163 #ifdef SQLITE_CONFIG_PMASZ
164 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_PMASZ, unsigned int);
165 #endif
166 #ifdef SQLITE_CONFIG_STMTJRNL_SPILL
167 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_STMTJRNL_SPILL, int);
168 #endif
169 #ifdef SQLITE_CONFIG_SORTERREF_SIZE
170 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_SORTERREF_SIZE, int);
171 #endif
172 #ifdef SQLITE_CONFIG_MEMDB_MAXSIZE
173 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_MEMDB_MAXSIZE, int64_t);
174 #endif
175 #ifdef SQLITE_CONFIG_ROWID_IN_VIEW
176 SQLITEPP_DEFINE_OPTION_N( SQLITE_CONFIG_ROWID_IN_VIEW, int);
177 #endif
178
179 //@ [Config Options]
180
181 #undef SQLITEPP_DEFINE_OPTION_0
182 #undef SQLITEPP_DEFINE_OPTION_N
183
184 SQLITEPP_SUPPRESS_SILLY_VARARG_WARNING_END
185
186 }
188}
189
190
191#endif
192
Exception used to report any SQLite errors.
Definition exception_iface.hpp:166
sqlite3_config
T forward(T... args)
void initialize()
Initialize the SQLite library.
Definition global_iface.hpp:33
auto config(Args &&...args) -> void
Configures SQLite library.
Definition global_iface.hpp:90
void shutdown() noexcept
Deinitialize the SQLite library.
Definition global_iface.hpp:47
sqlite3_initialize
ThinSQLite++ namespace.
Definition backup_iface.hpp:17
#define SQLITE_OK