mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
parent
bf8c495b69
commit
ffe605150a
@ -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 }
|
||||||
|
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