mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
Unlock notification
Test added
This commit is contained in:
parent
154a70d41b
commit
5fd76aa54b
@ -35,8 +35,8 @@ impl RawStatement {
|
|||||||
loop {
|
loop {
|
||||||
rc = unsafe { ffi::sqlite3_step(self.0) };
|
rc = unsafe { ffi::sqlite3_step(self.0) };
|
||||||
if rc == ffi::SQLITE_LOCKED {
|
if rc == ffi::SQLITE_LOCKED {
|
||||||
if unsafe { ffi::sqlite3_extended_errcode(self.1) } !=
|
if unsafe { ffi::sqlite3_extended_errcode(self.1) }
|
||||||
ffi::SQLITE_LOCKED_SHAREDCACHE
|
!= ffi::SQLITE_LOCKED_SHAREDCACHE
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -82,3 +82,36 @@ pub fn wait_for_unlock_notify(db: *mut ffi::sqlite3) -> c_int {
|
|||||||
pub fn wait_for_unlock_notify(_db: *mut ffi::sqlite3) -> c_int {
|
pub fn wait_for_unlock_notify(_db: *mut ffi::sqlite3) -> c_int {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unlock_notify")]
|
||||||
|
#[cfg(test)]
|
||||||
|
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};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unlock_notify() {
|
||||||
|
let url = "file::memory:?cache=shared";
|
||||||
|
let flags = SQLITE_OPEN_READ_WRITE | 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 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();
|
||||||
|
let ten_millis = time::Duration::from_millis(10);
|
||||||
|
thread::sleep(ten_millis);
|
||||||
|
tx2.commit().unwrap();
|
||||||
|
});
|
||||||
|
assert_eq!(receiver.recv().unwrap(), 1);
|
||||||
|
let the_answer: Result<i64> = db1.query_row("SELECT x FROM foo", &[], |r| r.get(0));
|
||||||
|
assert_eq!(42i64, the_answer.unwrap());
|
||||||
|
child.join().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user