mirror of
https://github.com/isar/rusqlite.git
synced 2025-11-13 16:28:55 +08:00
17
src/cache.rs
17
src/cache.rs
@@ -44,6 +44,10 @@ impl Connection {
|
||||
pub fn set_prepared_statement_cache_capacity(&self, capacity: usize) {
|
||||
self.cache.set_capacity(capacity)
|
||||
}
|
||||
|
||||
pub fn flush_prepared_statement_cache(&self) {
|
||||
self.cache.flush()
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepared statements LRU cache.
|
||||
@@ -133,6 +137,11 @@ impl StatementCache {
|
||||
let sql = String::from_utf8_lossy(stmt.sql().to_bytes()).to_string();
|
||||
cache.insert(sql, stmt);
|
||||
}
|
||||
|
||||
fn flush(&self) {
|
||||
let mut cache = self.0.borrow_mut();
|
||||
cache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -268,4 +277,12 @@ mod test {
|
||||
.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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user