Try to introduce a CachedStatement struct.

This commit is contained in:
Gwenael Treguier 2015-12-16 19:42:03 +01:00
parent 880a78ae83
commit 9257987b37

View File

@ -9,10 +9,28 @@ use self::lru_cache::LruCache;
/// FIXME limitation: the same SQL can be cached only once... /// FIXME limitation: the same SQL can be cached only once...
#[derive(Debug)] #[derive(Debug)]
pub struct StatementCache<'conn> { pub struct StatementCache<'conn> {
pub conn: &'conn Connection, conn: &'conn Connection,
cache: LruCache<String, Statement<'conn>>, 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> { impl<'conn> StatementCache<'conn> {
/// Create a statement cache. /// Create a statement cache.
pub fn new(conn: &'conn Connection, capacity: usize) -> StatementCache<'conn> { pub fn new(conn: &'conn Connection, capacity: usize) -> StatementCache<'conn> {