Factorize code

This commit is contained in:
gwenn 2020-02-09 12:21:20 +01:00
parent 4d58a43b38
commit 7d1d6024e9

View File

@ -411,12 +411,7 @@ impl Connection {
/// ///
/// Will return `Err` if the underlying SQLite open call fails. /// Will return `Err` if the underlying SQLite open call fails.
pub fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Connection> { pub fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Connection> {
let c_memory = str_to_cstring(":memory:")?; Connection::open_with_flags(":memory:", flags)
InnerConnection::open_with_flags(&c_memory, flags, None).map(|db| Connection {
db: RefCell::new(db),
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
path: None,
})
} }
/// Open a new connection to an in-memory SQLite database using the specific /// Open a new connection to an in-memory SQLite database using the specific
@ -430,13 +425,7 @@ impl Connection {
/// Will return `Err` if vfs` cannot be converted to a C-compatible /// Will return `Err` if vfs` cannot be converted to a C-compatible
/// string or if the underlying SQLite open call fails. /// string or if the underlying SQLite open call fails.
pub fn open_in_memory_with_flags_and_vfs(flags: OpenFlags, vfs: &str) -> Result<Connection> { pub fn open_in_memory_with_flags_and_vfs(flags: OpenFlags, vfs: &str) -> Result<Connection> {
let c_memory = str_to_cstring(":memory:")?; Connection::open_with_flags_and_vfs(":memory:", flags, vfs)
let c_vfs = str_to_cstring(vfs)?;
InnerConnection::open_with_flags(&c_memory, flags, Some(&c_vfs)).map(|db| Connection {
db: RefCell::new(db),
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
path: None,
})
} }
/// Convenience method to run multiple SQL statements (that cannot take any /// Convenience method to run multiple SQL statements (that cannot take any