1
1
#pragma once
2
2
3
+ #include < cassert>
3
4
#include < string>
4
5
#include < functional>
5
6
#include < stdexcept>
@@ -213,7 +214,7 @@ namespace sqlite {
213
214
std::is_floating_point<Type>::value
214
215
|| std::is_integral<Type>::value
215
216
|| std::is_same<sqlite_int64, Type>::value
216
- > { };
217
+ > { };
217
218
218
219
219
220
template <typename T> friend database_binder& operator <<(database_binder& db, const T& val);
@@ -297,6 +298,10 @@ namespace sqlite {
297
298
}
298
299
};
299
300
301
+ struct sqlite_config {
302
+ std::string key{};
303
+ };
304
+
300
305
class database {
301
306
private:
302
307
std::shared_ptr<sqlite3> _db;
@@ -318,6 +323,18 @@ namespace sqlite {
318
323
database (std::shared_ptr<sqlite3> db):
319
324
_db (db) {}
320
325
326
+ database (const std::string &db_name, const sqlite_config &config):
327
+ database (std::u16string(db_name.begin(), db_name.end()), config) {}
328
+
329
+ database (const std::u16string &db_name, const sqlite_config &config): database(db_name) {
330
+ #ifdef SQLITE_HAS_CODEC
331
+ if (!config.key .empty ()) set_key (config.key );
332
+ #else
333
+ assert (config.key .empty () && " Encryption supported is disabled." );
334
+ (void )config; // Suppress unused warning
335
+ #endif
336
+ }
337
+
321
338
database_binder operator <<(const std::string& sql) {
322
339
return database_binder (_db, sql);
323
340
}
@@ -341,13 +358,6 @@ namespace sqlite {
341
358
}
342
359
343
360
#ifdef SQLITE_HAS_CODEC
344
- database (const std::string &db_name, const std::string &key): database(db_name) {
345
- set_key (key);
346
- }
347
- database (const std::u16string &db_name, const std::string &key): database(db_name) {
348
- set_key (key);
349
- }
350
-
351
361
void set_key (const std::string &key) {
352
362
if (auto ret = sqlite3_key (_db.get (), key.data (), key.size ()))
353
363
exceptions::throw_sqlite_error (ret);
0 commit comments