From c612a44207ba6eeb6dd6051b0d6640b0e6649838 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 24 Mar 2018 10:15:10 +0100 Subject: [PATCH] Fix errors relative to OpenFlags Also handle extended error codes. --- .travis.yml | 1 + src/lib.rs | 2 +- src/unlock_notify.rs | 16 ++++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index de9a910..d3aa772 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ script: - cargo test --features serde_json - cargo test --features bundled - 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 buildtime_bindgen" - cargo test --features "backup blob chrono functions hooks limits load_extension serde_json trace bundled" diff --git a/src/lib.rs b/src/lib.rs index 8a2df1c..d9389ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -875,7 +875,7 @@ impl InnerConnection { &mut c_stmt, ptr::null_mut(), ); - if rc != ffi::SQLITE_LOCKED { + if (rc & 0xFF) != ffi::SQLITE_LOCKED { break; } rc = unlock_notify::wait_for_unlock_notify(self.db); diff --git a/src/unlock_notify.rs b/src/unlock_notify.rs index 724358f..5aabfd2 100644 --- a/src/unlock_notify.rs +++ b/src/unlock_notify.rs @@ -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, ) }; - 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 { un.wait(); } @@ -89,27 +91,25 @@ mod test { use std::sync::mpsc::sync_channel; use std::thread; use std::time; - use {Connection, Result, Transaction, TransactionBehavior, SQLITE_OPEN_READ_WRITE, - SQLITE_OPEN_URI}; + use {Connection, OpenFlags, Result, Transaction, TransactionBehavior}; #[test] fn test_unlock_notify() { 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(); db1.execute_batch("CREATE TABLE foo (x)").unwrap(); - let (sender, receiver) = sync_channel(0); - let sender2 = sender.clone(); + let (rx, tx) = sync_channel(0); let child = thread::spawn(move || { let mut db2 = Connection::open_with_flags(url, flags).unwrap(); let tx2 = Transaction::new(&mut db2, TransactionBehavior::Immediate).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); thread::sleep(ten_millis); tx2.commit().unwrap(); }); - assert_eq!(receiver.recv().unwrap(), 1); + assert_eq!(tx.recv().unwrap(), 1); let the_answer: Result = db1.query_row("SELECT x FROM foo", &[], |r| r.get(0)); assert_eq!(42i64, the_answer.unwrap()); child.join().unwrap();