Add Failure documentation.

This commit is contained in:
Gwenael Treguier 2015-12-06 19:57:20 +01:00
parent fa03bcd564
commit 7ab79d6de6

View File

@ -21,6 +21,10 @@ impl<'conn> StatementCache<'conn> {
/// Search the cache for a prepared-statement object that implements `sql`. /// Search the cache for a prepared-statement object that implements `sql`.
// If no such prepared-statement can be found, allocate and prepare a new one. // If no such prepared-statement can be found, allocate and prepare a new one.
///
/// # Failure
///
/// Will return `Err` if no cached statement can be found and the underlying SQLite prepare call fails.
pub fn get(&mut self, sql: &str) -> SqliteResult<SqliteStatement<'conn>> { pub fn get(&mut self, sql: &str) -> SqliteResult<SqliteStatement<'conn>> {
let stmt = self.cache.remove(sql); let stmt = self.cache.remove(sql);
match stmt { match stmt {
@ -32,11 +36,16 @@ impl<'conn> StatementCache<'conn> {
/// If `discard` is true, then the statement is deleted immediately. /// If `discard` is true, then the statement is deleted immediately.
/// Otherwise it is added to the LRU list and may be returned /// Otherwise it is added to the LRU list and may be returned
/// by a subsequent call to `get()`. /// by a subsequent call to `get()`.
///
/// # Failure
///
/// Will return `Err` if `stmt` (or the already cached statement implementing the same SQL) statement is `discard`ed
/// and the underlying SQLite finalize call fails.
pub fn release(&mut self, stmt: SqliteStatement<'conn>, discard: bool) -> SqliteResult<()> { pub fn release(&mut self, stmt: SqliteStatement<'conn>, discard: bool) -> SqliteResult<()> {
if discard { if discard {
return stmt.finalize(); return stmt.finalize();
} }
// FIXME stmt.reset_if_needed(); stmt.reset_if_needed();
// clear bindings ??? // clear bindings ???
self.cache.insert(stmt.sql(), stmt).map_or(Ok(()), |stmt| stmt.finalize()) self.cache.insert(stmt.sql(), stmt).map_or(Ok(()), |stmt| stmt.finalize())
} }