From 9178e3f45225e4c07d976a0d144c12e9af3a44d5 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 6 Apr 2018 22:27:07 +0200 Subject: [PATCH 1/2] Use `rerun-if-env-changed` in libsqlite3-sys Fix #329 --- libsqlite3-sys/build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index 0757d9f..a70f38d 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -83,6 +83,11 @@ mod build { fn find_sqlite() -> HeaderLocation { let link_lib = link_lib(); + println!("cargo:rerun-if-env-changed={}_INCLUDE_DIR", env_prefix()); + println!("cargo:rerun-if-env-changed={}_LIB_DIR", env_prefix()); + if cfg!(target_os="windows") { + println!("cargo:rerun-if-env-changed=PATH"); + } // Allow users to specify where to find SQLite. if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) { println!("cargo:rustc-link-lib={}", link_lib); From 6855b5052d3016cf3c6ce521248430a4ad22b630 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 12 May 2018 18:35:08 +0200 Subject: [PATCH 2/2] Ensure connection can be safely returned to a pool (#353) * Add binding to sqlite3_get_autocommit. * Add binding to sqlite3_stmt_busy. * Disable test_is_busy by default --- src/lib.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 69a039a..21cfa15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -573,6 +573,18 @@ impl Connection { fn changes(&self) -> c_int { self.db.borrow_mut().changes() } + + /// Test for auto-commit mode. + /// Autocommit mode is on by default. + pub fn is_autocommit(&self) -> bool { + self.db.borrow().is_autocommit() + } + + /// Determine if all associated prepared statements have been reset. + #[cfg(feature = "bundled")] + pub fn is_busy(&self) -> bool { + self.db.borrow().is_busy() + } } impl fmt::Debug for Connection { @@ -903,6 +915,25 @@ impl InnerConnection { unsafe { ffi::sqlite3_changes(self.db()) } } + fn is_autocommit(&self) -> bool { + unsafe { ffi::sqlite3_get_autocommit(self.db()) != 0 } + } + + #[cfg(feature = "bundled")] // 3.8.6 + fn is_busy(&self) -> bool { + let db = self.db(); + unsafe { + let mut stmt = ffi::sqlite3_next_stmt(db, ptr::null_mut()); + while !stmt.is_null() { + if ffi::sqlite3_stmt_busy(stmt) != 0 { + return true; + } + stmt = ffi::sqlite3_next_stmt(db, stmt); + } + } + return false; + } + #[cfg(not(feature = "hooks"))] fn remove_hooks(&mut self) { } @@ -1223,6 +1254,30 @@ mod test { assert_eq!(db.last_insert_rowid(), 10); } + #[test] + fn test_is_autocommit() { + let db = checked_memory_handle(); + assert!(db.is_autocommit(), + "autocommit expected to be active by default"); + } + + #[test] + #[cfg(feature = "bundled")] + fn test_is_busy() { + let db = checked_memory_handle(); + assert!(!db.is_busy()); + let mut stmt = db.prepare("PRAGMA schema_version").unwrap(); + assert!(!db.is_busy()); + { + let mut rows = stmt.query(&[]).unwrap(); + assert!(!db.is_busy()); + let row = rows.next(); + assert!(db.is_busy()); + assert!(row.is_some()); + } + assert!(!db.is_busy()); + } + #[test] fn test_statement_debugging() { let db = checked_memory_handle();