mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-05-06 14:02:13 +00:00
Read the error message when sqlite3_open_v2 fails
This commit is contained in:
parent
84064daa9d
commit
fc2ea5aa19
@ -28,25 +28,27 @@ impl Connection {
|
|||||||
pub fn open_with_flags<T: AsRef<Path>>(path: T, flags: OpenFlags) -> Result<Connection> {
|
pub fn open_with_flags<T: AsRef<Path>>(path: T, flags: OpenFlags) -> Result<Connection> {
|
||||||
let mut raw = 0 as *mut _;
|
let mut raw = 0 as *mut _;
|
||||||
unsafe {
|
unsafe {
|
||||||
let ret = ffi::sqlite3_open_v2(
|
let code = ffi::sqlite3_open_v2(
|
||||||
path_to_cstr!(path.as_ref()).as_ptr(),
|
path_to_cstr!(path.as_ref()).as_ptr(),
|
||||||
&mut raw,
|
&mut raw,
|
||||||
flags.0,
|
flags.0,
|
||||||
0 as *const _,
|
0 as *const _,
|
||||||
);
|
);
|
||||||
|
match code {
|
||||||
// Explicitly close the connection on error.
|
|
||||||
// This is a quirk of the C API, where the database handle
|
|
||||||
// (raw) is unconditionally allocated.
|
|
||||||
match ret {
|
|
||||||
ffi::SQLITE_OK => {}
|
ffi::SQLITE_OK => {}
|
||||||
code => {
|
code => match ::last_error(raw) {
|
||||||
ffi::sqlite3_close(raw);
|
Some(error) => {
|
||||||
return Err(::Error {
|
ffi::sqlite3_close(raw);
|
||||||
code: Some(code as isize),
|
return Err(error);
|
||||||
message: None,
|
}
|
||||||
});
|
_ => {
|
||||||
}
|
ffi::sqlite3_close(raw);
|
||||||
|
return Err(::Error {
|
||||||
|
code: Some(code as isize),
|
||||||
|
message: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Connection {
|
Ok(Connection {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user