Skip to content

Commit 2c9cbf6

Browse files
committed
Minimal SQLCipher support
1 parent cf01458 commit 2c9cbf6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,34 @@ namespace sqlite {
340340
return sqlite3_last_insert_rowid(_db.get());
341341
}
342342

343+
#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+
void set_key(const std::string &key) {
352+
if(auto ret = sqlite3_key(_db.get(), key.data(), key.size()))
353+
exceptions::throw_sqlite_error(ret);
354+
}
355+
356+
void set_key(const std::string &key, const std::string &db_name) {
357+
if(auto ret = sqlite3_key_v2(_db.get(), db_name.c_str(), key.data(), key.size()))
358+
exceptions::throw_sqlite_error(ret);
359+
}
360+
361+
void rekey(const std::string &new_key) {
362+
if(auto ret = sqlite3_rekey(_db.get(), new_key.data(), new_key.size()))
363+
exceptions::throw_sqlite_error(ret);
364+
}
365+
366+
void rekey(const std::string &new_key, const std::string &db_name) {
367+
if(auto ret = sqlite3_rekey_v2(_db.get(), db_name.c_str(), new_key.data(), new_key.size()))
368+
exceptions::throw_sqlite_error(ret);
369+
}
370+
#endif
343371
};
344372

345373
template<std::size_t Count>

0 commit comments

Comments
 (0)