diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index fce970139..6a09e851b 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -193,9 +193,9 @@ impl Cursor { } pub fn close(&self) -> PyResult<()> { - Err(PyErr::new::( - "close() is not supported in this version", - )) + self.conn.close()?; + + Ok(()) } #[pyo3(signature = (sql, parameters=None))] @@ -244,8 +244,12 @@ impl Connection { }) } - pub fn close(&self) { - drop(self.conn.clone()); + pub fn close(&self) -> PyResult<()> { + self.conn.close().map_err(|e| { + PyErr::new::(format!("Failed to close connection: {:?}", e)) + })?; + + Ok(()) } pub fn commit(&self) -> PyResult<()> { @@ -281,6 +285,14 @@ impl Connection { } } +impl Drop for Connection { + fn drop(&mut self) { + self.conn + .close() + .expect("Failed to drop (close) connection"); + } +} + #[allow(clippy::arc_with_non_send_sync)] #[pyfunction] pub fn connect(path: &str) -> Result {