Fix compilation errors

This commit is contained in:
gwenn 2020-02-09 12:08:25 +01:00
parent 9e17a0b28e
commit 4d58a43b38
2 changed files with 23 additions and 14 deletions

View File

@ -59,7 +59,11 @@ impl InnerConnection {
} }
} }
pub fn open_with_flags(c_path: &CString, flags: OpenFlags, vfs: Option(&CString)) -> Result<InnerConnection> { pub fn open_with_flags(
c_path: &CString,
flags: OpenFlags,
vfs: Option<&CString>,
) -> Result<InnerConnection> {
#[cfg(not(feature = "bundled"))] #[cfg(not(feature = "bundled"))]
ensure_valid_sqlite_version(); ensure_valid_sqlite_version();
ensure_safe_sqlite_threading_mode()?; ensure_safe_sqlite_threading_mode()?;
@ -79,15 +83,14 @@ impl InnerConnection {
)); ));
} }
z_vfs = match(vfs) { let z_vfs = match vfs {
Some(c_vfs) => c_vfs.as_ptr(), Some(c_vfs) => c_vfs.as_ptr(),
None => ptr::null() None => ptr::null(),
} };
unsafe { unsafe {
let mut db = MaybeUninit::uninit(); let mut db = MaybeUninit::uninit();
let r = let r = ffi::sqlite3_open_v2(c_path.as_ptr(), db.as_mut_ptr(), flags.bits(), z_vfs);
ffi::sqlite3_open_v2(c_path.as_ptr(), db.as_mut_ptr(), flags.bits(), z_vfs);
let db: *mut ffi::sqlite3 = db.assume_init(); let db: *mut ffi::sqlite3 = db.assume_init();
if r != ffi::SQLITE_OK { if r != ffi::SQLITE_OK {
let e = if db.is_null() { let e = if db.is_null() {

View File

@ -347,7 +347,7 @@ impl Connection {
/// string or if the underlying SQLite open call fails. /// string or if the underlying SQLite open call fails.
pub fn open<P: AsRef<Path>>(path: P) -> Result<Connection> { pub fn open<P: AsRef<Path>>(path: P) -> Result<Connection> {
let flags = OpenFlags::default(); let flags = OpenFlags::default();
Connection::open_with_flags(path, flags, None) Connection::open_with_flags(path, flags)
} }
/// Open a new connection to an in-memory SQLite database. /// Open a new connection to an in-memory SQLite database.
@ -378,19 +378,24 @@ impl Connection {
}) })
} }
/// Open a new connection to a SQLite database using the specific flags and vfs name. /// Open a new connection to a SQLite database using the specific flags and
/// vfs name.
/// ///
/// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a description of valid /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a description of valid
/// flag combinations. /// flag combinations.
/// ///
/// # Failure /// # Failure
/// ///
/// Will return `Err` if either `path` or `vfs` cannot be converted to a C-compatible /// Will return `Err` if either `path` or `vfs` cannot be converted to a
/// string or if the underlying SQLite open call fails. /// C-compatible string or if the underlying SQLite open call fails.
pub fn open_with_flags_and_vfs<P: AsRef<Path>>(path: P, flags: OpenFlags, vfs: &str) -> Result<Connection> { pub fn open_with_flags_and_vfs<P: AsRef<Path>>(
path: P,
flags: OpenFlags,
vfs: &str,
) -> Result<Connection> {
let c_path = path_to_cstring(path.as_ref())?; let c_path = path_to_cstring(path.as_ref())?;
let c_vfs = str_to_cstring(vfs)?; let c_vfs = str_to_cstring(vfs)?;
InnerConnection::open_with_flags(&c_path, flags, Some(c_vfs)).map(|db| Connection { InnerConnection::open_with_flags(&c_path, flags, Some(&c_vfs)).map(|db| Connection {
db: RefCell::new(db), db: RefCell::new(db),
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY), cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
path: Some(path.as_ref().to_path_buf()), path: Some(path.as_ref().to_path_buf()),
@ -414,7 +419,8 @@ impl Connection {
}) })
} }
/// Open a new connection to an in-memory SQLite database using the specific flags and vfs name. /// Open a new connection to an in-memory SQLite database using the specific
/// flags and vfs name.
/// ///
/// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a description of valid /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a description of valid
/// flag combinations. /// flag combinations.
@ -426,7 +432,7 @@ impl Connection {
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:")?; let c_memory = str_to_cstring(":memory:")?;
let c_vfs = str_to_cstring(vfs)?; let c_vfs = str_to_cstring(vfs)?;
InnerConnection::open_with_flags(&c_memory, flags, Some(c_vfs)).map(|db| Connection { InnerConnection::open_with_flags(&c_memory, flags, Some(&c_vfs)).map(|db| Connection {
db: RefCell::new(db), db: RefCell::new(db),
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY), cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
path: None, path: None,