diff --git a/diesel/src/sqlite/connection/raw.rs b/diesel/src/sqlite/connection/raw.rs index 2c9686f5f0e3..cdbf55072b25 100644 --- a/diesel/src/sqlite/connection/raw.rs +++ b/diesel/src/sqlite/connection/raw.rs @@ -13,12 +13,17 @@ pub struct RawConnection { pub internal_connection: *mut ffi::sqlite3, } +const BUSY_TIMEOUT: i32 = 5000; + impl RawConnection { pub fn establish(database_url: &str) -> ConnectionResult { let mut conn_pointer = ptr::null_mut(); let database_url = try!(CString::new(database_url)); let connection_status = unsafe { - ffi::sqlite3_open(database_url.as_ptr(), &mut conn_pointer) + match ffi::sqlite3_open(database_url.as_ptr(), &mut conn_pointer) { + ffi::SQLITE_OK => ffi::sqlite3_busy_timeout(conn_pointer, BUSY_TIMEOUT), + err_code => err_code, + } }; match connection_status { diff --git a/diesel/src/sqlite/connection/stmt.rs b/diesel/src/sqlite/connection/stmt.rs index 7686ed03cede..940e4a2749b2 100644 --- a/diesel/src/sqlite/connection/stmt.rs +++ b/diesel/src/sqlite/connection/stmt.rs @@ -123,6 +123,8 @@ impl Statement { match unsafe { ffi::sqlite3_step(self.inner_statement) } { ffi::SQLITE_DONE => None, ffi::SQLITE_ROW => Some(SqliteRow::new(self.inner_statement)), + // TODO: better error handling + ffi::SQLITE_BUSY => None, error => panic!("{}", super::error_message(error)), } }