diff --git a/src/inner_connection.rs b/src/inner_connection.rs index 056f83a..801ea0f 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -61,7 +61,7 @@ impl InnerConnection { pub fn open_with_flags( c_path: &CStr, - flags: OpenFlags, + mut flags: OpenFlags, vfs: Option<&CStr>, ) -> Result<InnerConnection> { ensure_safe_sqlite_threading_mode()?; @@ -71,6 +71,16 @@ impl InnerConnection { None => ptr::null(), }; + // turn on extended results code before opening database to have a better diagnostic if a failure happens + let exrescode = if version_number() >= 3_037_000 { + if !flags.contains(OpenFlags::SQLITE_OPEN_EXRESCODE) { + flags |= OpenFlags::SQLITE_OPEN_EXRESCODE; + } + true + } else { + false // flag SQLITE_OPEN_EXRESCODE is ignored by SQLite version < 3.37.0 + }; + unsafe { let mut db: *mut ffi::sqlite3 = ptr::null_mut(); let r = ffi::sqlite3_open_v2(c_path.as_ptr(), &mut db, flags.bits(), z_vfs); @@ -100,7 +110,7 @@ impl InnerConnection { } // attempt to turn on extended results code; don't fail if we can't. - if version_number() < 3_037_000 || !flags.contains(OpenFlags::SQLITE_OPEN_EXRESCODE) { + if !exrescode { ffi::sqlite3_extended_result_codes(db, 1); } diff --git a/src/lib.rs b/src/lib.rs index 2ca74bc..7572908 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1214,7 +1214,6 @@ impl Default for OpenFlags { | OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_NO_MUTEX | OpenFlags::SQLITE_OPEN_URI - | OpenFlags::SQLITE_OPEN_EXRESCODE } }