From 67092074538f7658b256f8e1f5e34abde959a46a Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 6 Jan 2017 14:32:27 -0500 Subject: [PATCH] Fix close() returning a useful connection on failure. --- src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e2dec86..b0ccaa9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -608,8 +608,11 @@ impl InnerConnection { fn close(&mut self) -> Result<()> { unsafe { let r = ffi::sqlite3_close(self.db()); - self.db = ptr::null_mut(); - self.decode_result(r) + let r = self.decode_result(r); + if r.is_ok() { + self.db = ptr::null_mut(); + } + r } } @@ -1277,13 +1280,14 @@ mod test { raw_stmt }; - let result = db.close(); - assert!(result.is_err()); + // now that we have an open statement, trying (and retrying) to close should fail. + let (db, _) = db.close().unwrap_err(); + let (db, _) = db.close().unwrap_err(); + let (db, _) = db.close().unwrap_err(); - // finalize the open statement so a second close will succeed + // finalize the open statement so a final close will succeed assert_eq!(ffi::SQLITE_OK, unsafe { ffi::sqlite3_finalize(raw_stmt) }); - let (db, _) = result.unwrap_err(); db.close().unwrap(); }