mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Factorize check on code returned by prepare/step.
This commit is contained in:
parent
c612a44207
commit
cccdf9735f
@ -875,10 +875,7 @@ impl InnerConnection {
|
||||
&mut c_stmt,
|
||||
ptr::null_mut(),
|
||||
);
|
||||
if (rc & 0xFF) != ffi::SQLITE_LOCKED {
|
||||
break;
|
||||
}
|
||||
rc = unlock_notify::wait_for_unlock_notify(self.db);
|
||||
rc = unlock_notify::wait_for_unlock_notify(self.db, rc);
|
||||
if rc != ffi::SQLITE_OK {
|
||||
break;
|
||||
}
|
||||
|
@ -34,16 +34,7 @@ impl RawStatement {
|
||||
let mut rc;
|
||||
loop {
|
||||
rc = unsafe { ffi::sqlite3_step(self.0) };
|
||||
if rc == ffi::SQLITE_LOCKED {
|
||||
if unsafe { ffi::sqlite3_extended_errcode(self.1) }
|
||||
!= ffi::SQLITE_LOCKED_SHAREDCACHE
|
||||
{
|
||||
break;
|
||||
}
|
||||
} else if rc != ffi::SQLITE_LOCKED_SHAREDCACHE {
|
||||
break;
|
||||
}
|
||||
rc = unlock_notify::wait_for_unlock_notify(self.1);
|
||||
rc = unlock_notify::wait_for_unlock_notify(self.1, rc);
|
||||
if rc != ffi::SQLITE_OK {
|
||||
break;
|
||||
}
|
||||
|
@ -61,7 +61,14 @@ unsafe extern "C" fn unlock_notify_cb(ap_arg: *mut *mut c_void, n_arg: c_int) {
|
||||
/// this case the caller should not retry the operation and should roll
|
||||
/// back the current transaction (if any).
|
||||
#[cfg(feature = "unlock_notify")]
|
||||
pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3) -> c_int {
|
||||
pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3, rc: c_int) -> c_int {
|
||||
if rc == ffi::SQLITE_LOCKED {
|
||||
if unsafe { ffi::sqlite3_extended_errcode(self.1) } != ffi::SQLITE_LOCKED_SHAREDCACHE {
|
||||
return rc;
|
||||
}
|
||||
} else if rc != ffi::SQLITE_LOCKED_SHAREDCACHE {
|
||||
return rc;
|
||||
}
|
||||
let mut un = UnlockNotification::new();
|
||||
/* Register for an unlock-notify callback. */
|
||||
let rc = unsafe {
|
||||
@ -71,9 +78,9 @@ pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3) -> c_int {
|
||||
&mut un as *mut UnlockNotification as *mut c_void,
|
||||
)
|
||||
};
|
||||
debug_assert!(rc == ffi::SQLITE_LOCKED ||
|
||||
rc == ffi::SQLITE_LOCKED_SHAREDCACHE ||
|
||||
rc == ffi::SQLITE_OK);
|
||||
debug_assert!(
|
||||
rc == ffi::SQLITE_LOCKED || rc == ffi::SQLITE_LOCKED_SHAREDCACHE || rc == ffi::SQLITE_OK
|
||||
);
|
||||
if rc == ffi::SQLITE_OK {
|
||||
un.wait();
|
||||
}
|
||||
@ -81,7 +88,7 @@ pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3) -> c_int {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "unlock_notify"))]
|
||||
pub fn wait_for_unlock_notify(_db: *mut ffi::sqlite3) -> c_int {
|
||||
pub fn wait_for_unlock_notify(_db: *mut ffi::sqlite3, _code: c_int) -> c_int {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user