mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Merge pull request #205 from jgallagher/fix-retry-close-failure
Fix close() returning a useful connection on failure.
This commit is contained in:
commit
b49e1d1a1c
16
src/lib.rs
16
src/lib.rs
@ -609,8 +609,11 @@ impl InnerConnection {
|
|||||||
fn close(&mut self) -> Result<()> {
|
fn close(&mut self) -> Result<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let r = ffi::sqlite3_close(self.db());
|
let r = ffi::sqlite3_close(self.db());
|
||||||
self.db = ptr::null_mut();
|
let r = self.decode_result(r);
|
||||||
self.decode_result(r)
|
if r.is_ok() {
|
||||||
|
self.db = ptr::null_mut();
|
||||||
|
}
|
||||||
|
r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1278,13 +1281,14 @@ mod test {
|
|||||||
raw_stmt
|
raw_stmt
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = db.close();
|
// now that we have an open statement, trying (and retrying) to close should fail.
|
||||||
assert!(result.is_err());
|
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) });
|
assert_eq!(ffi::SQLITE_OK, unsafe { ffi::sqlite3_finalize(raw_stmt) });
|
||||||
|
|
||||||
let (db, _) = result.unwrap_err();
|
|
||||||
db.close().unwrap();
|
db.close().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user