mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-27 03:51:38 +08:00
Merge pull request #194 from jgallagher/gwenn-flush-cache
Ensure cache is flushed when closing the connection
This commit is contained in:
commit
a0b0f77b3e
@ -22,7 +22,7 @@ trace = []
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
time = "~0.1.0"
|
time = "~0.1.0"
|
||||||
bitflags = "0.7"
|
bitflags = "0.7"
|
||||||
lru-cache = "0.0.7"
|
lru-cache = "0.1.0"
|
||||||
libc = "~0.2"
|
libc = "~0.2"
|
||||||
chrono = { version = "~0.2", optional = true }
|
chrono = { version = "~0.2", optional = true }
|
||||||
serde_json = { version = "0.6", optional = true }
|
serde_json = { version = "0.6", optional = true }
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
https://github.com/jgallagher/rusqlite/pull/184.
|
https://github.com/jgallagher/rusqlite/pull/184.
|
||||||
* Added `#[deprecated(since = "...", note = "...")]` flags (new in Rust 1.9 for libraries) to
|
* Added `#[deprecated(since = "...", note = "...")]` flags (new in Rust 1.9 for libraries) to
|
||||||
all deprecated APIs.
|
all deprecated APIs.
|
||||||
|
* Fixed a bug where using cached prepared statements resulted in attempting to close a connection
|
||||||
|
failing with `DatabaseBusy`; see https://github.com/jgallagher/rusqlite/issues/186.
|
||||||
|
|
||||||
# Version 0.7.3 (2016-06-01)
|
# Version 0.7.3 (2016-06-01)
|
||||||
|
|
||||||
|
17
src/cache.rs
17
src/cache.rs
@ -44,6 +44,10 @@ impl Connection {
|
|||||||
pub fn set_prepared_statement_cache_capacity(&self, capacity: usize) {
|
pub fn set_prepared_statement_cache_capacity(&self, capacity: usize) {
|
||||||
self.cache.set_capacity(capacity)
|
self.cache.set_capacity(capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn flush_prepared_statement_cache(&self) {
|
||||||
|
self.cache.flush()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepared statements LRU cache.
|
/// Prepared statements LRU cache.
|
||||||
@ -133,6 +137,11 @@ impl StatementCache {
|
|||||||
let sql = String::from_utf8_lossy(stmt.sql().to_bytes()).to_string();
|
let sql = String::from_utf8_lossy(stmt.sql().to_bytes()).to_string();
|
||||||
cache.insert(sql, stmt);
|
cache.insert(sql, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flush(&self) {
|
||||||
|
let mut cache = self.0.borrow_mut();
|
||||||
|
cache.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -268,4 +277,12 @@ mod test {
|
|||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_connection_close() {
|
||||||
|
let conn = Connection::open_in_memory().unwrap();
|
||||||
|
conn.prepare_cached("SELECT * FROM sqlite_master;").unwrap();
|
||||||
|
|
||||||
|
conn.close().expect("connection not closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,6 +405,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite call fails.
|
/// Will return `Err` if the underlying SQLite call fails.
|
||||||
pub fn close(self) -> Result<()> {
|
pub fn close(self) -> Result<()> {
|
||||||
|
self.flush_prepared_statement_cache();
|
||||||
let mut db = self.db.borrow_mut();
|
let mut db = self.db.borrow_mut();
|
||||||
db.close()
|
db.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user