Skip to content

Commit

Permalink
step should not panic when SQLITE_BUSY encountered
Browse files Browse the repository at this point in the history
this commit only logs the error, but can more refine grained
method should be used.

reference: https://github.com/jgallagher/rusqlite/blob/master/src/row.rs#L43
  • Loading branch information
king6cong committed Jun 4, 2017
1 parent a6339a0 commit bf9acb2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ time = { version = "0.1", optional = true }
url = { version = "1.4.0", optional = true }
uuid = { version = ">=0.2.0, <0.6.0", optional = true, features = ["use_std"] }
ipnetwork = { version = "0.12.2", optional = true }
log = "0.3"

[dev-dependencies]
cfg-if = "0.1.0"
Expand Down
2 changes: 0 additions & 2 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))]

extern crate byteorder;
#[macro_use]
extern crate log;

#[macro_use]
mod macros;
Expand Down
23 changes: 9 additions & 14 deletions diesel/src/sqlite/connection/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,23 @@ pub struct RawConnection {
pub internal_connection: *mut ffi::sqlite3,
}

const BUSY_TIMEOUT: i32 = 5000;

impl RawConnection {
pub fn establish(database_url: &str) -> ConnectionResult<Self> {
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 {
ffi::SQLITE_OK => {
let r = unsafe {
ffi::sqlite3_busy_timeout(conn_pointer, 5000)
};

if r != ffi::SQLITE_OK {
warn!("sqlite3_busy_timeout error: {:?}", r);
}

Ok(RawConnection {
internal_connection: conn_pointer,
})
},
ffi::SQLITE_OK => Ok(RawConnection {
internal_connection: conn_pointer,
}),
err_code => {
let message = super::error_message(err_code);
Err(ConnectionError::BadConnection(message.into()))
Expand Down
2 changes: 2 additions & 0 deletions diesel/src/sqlite/connection/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
Expand Down

0 comments on commit bf9acb2

Please sign in to comment.