From a29fed8512a8ba6ef5136dcd448eb63087db04ef Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 10 Mar 2024 10:17:03 +0100 Subject: [PATCH] Add binding to sqlite3_is_interrupted --- src/inner_connection.rs | 5 +++++ src/lib.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/inner_connection.rs b/src/inner_connection.rs index 8d86a48..0070b75 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -375,6 +375,11 @@ impl InnerConnection { pub fn release_memory(&self) -> Result<()> { self.decode_result(unsafe { ffi::sqlite3_db_release_memory(self.db) }) } + + #[cfg(feature = "modern_sqlite")] // 3.41.0 + pub fn is_interrupted(&self) -> bool { + unsafe { ffi::sqlite3_is_interrupted(self.db) == 1 } + } } impl Drop for InnerConnection { diff --git a/src/lib.rs b/src/lib.rs index 8a25e70..d6c8156 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1037,6 +1037,12 @@ impl Connection { pub fn is_readonly(&self, db_name: DatabaseName<'_>) -> Result { self.db.borrow().db_readonly(db_name) } + + /// Determine whether or not an interrupt is currently in effect + #[cfg(feature = "modern_sqlite")] // 3.41.0 + pub fn is_interrupted(&self) -> bool { + self.db.borrow().is_interrupted() + } } impl fmt::Debug for Connection { @@ -2206,4 +2212,14 @@ mod test { assert_eq!((v1.as_str(), v2), (name, age)); Ok(()) } + + #[test] + #[cfg(feature = "modern_sqlite")] + fn test_is_interrupted() -> Result<()> { + let db = Connection::open_in_memory()?; + assert!(!db.is_interrupted()); + db.get_interrupt_handle().interrupt(); + assert!(db.is_interrupted()); + Ok(()) + } }