From 8e1ce5cf9c964146c4ae02bc3c07b4e98ccae159 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Mon, 16 May 2016 14:11:44 -0500 Subject: [PATCH] Fuse a `Rows` iterator once it fetches the final row. --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e2e6e1..5b6dd81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1004,7 +1004,7 @@ pub type SqliteRows<'stmt> = Rows<'stmt>; pub struct Rows<'stmt> { stmt: &'stmt Statement<'stmt>, current_row: Rc>, - failed: bool, + done: bool, } impl<'stmt> Rows<'stmt> { @@ -1012,7 +1012,7 @@ impl<'stmt> Rows<'stmt> { Rows { stmt: stmt, current_row: Rc::new(Cell::new(0)), - failed: false, + done: false, } } @@ -1028,7 +1028,7 @@ impl<'stmt> Iterator for Rows<'stmt> { type Item = Result>; fn next(&mut self) -> Option>> { - if self.failed { + if self.done { return None; } match unsafe { ffi::sqlite3_step(self.stmt.stmt) } { @@ -1041,9 +1041,12 @@ impl<'stmt> Iterator for Rows<'stmt> { row_idx: current_row, })) } - ffi::SQLITE_DONE => None, + ffi::SQLITE_DONE => { + self.done = true; + None + } code => { - self.failed = true; + self.done = true; Some(Err(self.stmt.conn.decode_result(code).unwrap_err())) } }