mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Try to introduce a CachedStatement struct.
This commit is contained in:
parent
880a78ae83
commit
9257987b37
20
src/cache.rs
20
src/cache.rs
@ -9,10 +9,28 @@ use self::lru_cache::LruCache;
|
||||
/// FIXME limitation: the same SQL can be cached only once...
|
||||
#[derive(Debug)]
|
||||
pub struct StatementCache<'conn> {
|
||||
pub conn: &'conn Connection,
|
||||
conn: &'conn Connection,
|
||||
cache: LruCache<String, Statement<'conn>>,
|
||||
}
|
||||
|
||||
pub struct CachedStatement<'conn> {
|
||||
stmt: Statement<'conn>,
|
||||
cache: &'conn StatementCache<'conn>,
|
||||
pub cacheable : bool,
|
||||
}
|
||||
|
||||
impl<'conn> Drop for CachedStatement<'conn> {
|
||||
#[allow(unused_must_use)]
|
||||
fn drop(&mut self) {
|
||||
if self.cacheable {
|
||||
// FIXME cannot borrow immutable borrowed content `*self.cache` as mutable
|
||||
//self.cache.release(self.stmt, false);
|
||||
} else {
|
||||
self.stmt.finalize_();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'conn> StatementCache<'conn> {
|
||||
/// Create a statement cache.
|
||||
pub fn new(conn: &'conn Connection, capacity: usize) -> StatementCache<'conn> {
|
||||
|
Loading…
Reference in New Issue
Block a user