Fix errors relative to OpenFlags

Also handle extended error codes.
This commit is contained in:
gwenn 2018-03-24 10:15:10 +01:00
parent 5fd76aa54b
commit c612a44207
3 changed files with 10 additions and 9 deletions

View File

@ -38,6 +38,7 @@ script:
- cargo test --features serde_json - cargo test --features serde_json
- cargo test --features bundled - cargo test --features bundled
- cargo test --features sqlcipher - cargo test --features sqlcipher
- cargo test --features "unlock_notify bundled"
- cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace" - cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace"
- cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace buildtime_bindgen" - cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace buildtime_bindgen"
- cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace bundled" - cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace bundled"

View File

@ -875,7 +875,7 @@ impl InnerConnection {
&mut c_stmt, &mut c_stmt,
ptr::null_mut(), ptr::null_mut(),
); );
if rc != ffi::SQLITE_LOCKED { if (rc & 0xFF) != ffi::SQLITE_LOCKED {
break; break;
} }
rc = unlock_notify::wait_for_unlock_notify(self.db); rc = unlock_notify::wait_for_unlock_notify(self.db);

View File

@ -71,7 +71,9 @@ pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3) -> c_int {
&mut un as *mut UnlockNotification as *mut c_void, &mut un as *mut UnlockNotification as *mut c_void,
) )
}; };
debug_assert!(rc == ffi::SQLITE_LOCKED || rc == ffi::SQLITE_OK); debug_assert!(rc == ffi::SQLITE_LOCKED ||
rc == ffi::SQLITE_LOCKED_SHAREDCACHE ||
rc == ffi::SQLITE_OK);
if rc == ffi::SQLITE_OK { if rc == ffi::SQLITE_OK {
un.wait(); un.wait();
} }
@ -89,27 +91,25 @@ mod test {
use std::sync::mpsc::sync_channel; use std::sync::mpsc::sync_channel;
use std::thread; use std::thread;
use std::time; use std::time;
use {Connection, Result, Transaction, TransactionBehavior, SQLITE_OPEN_READ_WRITE, use {Connection, OpenFlags, Result, Transaction, TransactionBehavior};
SQLITE_OPEN_URI};
#[test] #[test]
fn test_unlock_notify() { fn test_unlock_notify() {
let url = "file::memory:?cache=shared"; let url = "file::memory:?cache=shared";
let flags = SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_URI; let flags = OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_URI;
let db1 = Connection::open_with_flags(url, flags).unwrap(); let db1 = Connection::open_with_flags(url, flags).unwrap();
db1.execute_batch("CREATE TABLE foo (x)").unwrap(); db1.execute_batch("CREATE TABLE foo (x)").unwrap();
let (sender, receiver) = sync_channel(0); let (rx, tx) = sync_channel(0);
let sender2 = sender.clone();
let child = thread::spawn(move || { let child = thread::spawn(move || {
let mut db2 = Connection::open_with_flags(url, flags).unwrap(); let mut db2 = Connection::open_with_flags(url, flags).unwrap();
let tx2 = Transaction::new(&mut db2, TransactionBehavior::Immediate).unwrap(); let tx2 = Transaction::new(&mut db2, TransactionBehavior::Immediate).unwrap();
tx2.execute_batch("INSERT INTO foo VALUES (42)").unwrap(); tx2.execute_batch("INSERT INTO foo VALUES (42)").unwrap();
sender2.send(1).unwrap(); rx.send(1).unwrap();
let ten_millis = time::Duration::from_millis(10); let ten_millis = time::Duration::from_millis(10);
thread::sleep(ten_millis); thread::sleep(ten_millis);
tx2.commit().unwrap(); tx2.commit().unwrap();
}); });
assert_eq!(receiver.recv().unwrap(), 1); assert_eq!(tx.recv().unwrap(), 1);
let the_answer: Result<i64> = db1.query_row("SELECT x FROM foo", &[], |r| r.get(0)); let the_answer: Result<i64> = db1.query_row("SELECT x FROM foo", &[], |r| r.get(0));
assert_eq!(42i64, the_answer.unwrap()); assert_eq!(42i64, the_answer.unwrap());
child.join().unwrap(); child.join().unwrap();