core/sqlite: Add special case for sqlcipher key pragma when connecting. (#1587)

* core/sqlite: Add special case for sqlcipher key pragma when connecting.

* core/sqlite: Move std::fmt::Write import to module level.
This commit is contained in:
parazyd 2021-12-28 00:33:06 +01:00 committed by GitHub
parent 566b666df6
commit d258e8c681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ use crate::sqlite::connection::establish::establish;
use crate::sqlite::{SqliteConnectOptions, SqliteConnection};
use futures_core::future::BoxFuture;
use log::LevelFilter;
use std::fmt::Write;
use std::time::Duration;
impl ConnectOptions for SqliteConnectOptions {
@ -20,8 +21,18 @@ impl ConnectOptions for SqliteConnectOptions {
// send an initial sql statement comprised of options
let mut init = String::new();
// This is a special case for sqlcipher. When the `key` pragma
// is set, we have to make sure it's executed first in order.
if let Some(pragma_key_password) = self.pragmas.get("key") {
write!(init, "PRAGMA key = {}; ", pragma_key_password).ok();
}
for (key, value) in self.pragmas.iter() {
use std::fmt::Write;
// Since we've already written the possible `key` pragma
// above, we shall skip it now.
if key == "key" {
continue;
}
write!(init, "PRAGMA {} = {}; ", key, value).ok();
}