Fuse a Rows iterator once it fetches the final row.

This commit is contained in:
John Gallagher 2016-05-16 14:11:44 -05:00
parent 4a6c7b5329
commit 8e1ce5cf9c

View File

@ -1004,7 +1004,7 @@ pub type SqliteRows<'stmt> = Rows<'stmt>;
pub struct Rows<'stmt> { pub struct Rows<'stmt> {
stmt: &'stmt Statement<'stmt>, stmt: &'stmt Statement<'stmt>,
current_row: Rc<Cell<c_int>>, current_row: Rc<Cell<c_int>>,
failed: bool, done: bool,
} }
impl<'stmt> Rows<'stmt> { impl<'stmt> Rows<'stmt> {
@ -1012,7 +1012,7 @@ impl<'stmt> Rows<'stmt> {
Rows { Rows {
stmt: stmt, stmt: stmt,
current_row: Rc::new(Cell::new(0)), current_row: Rc::new(Cell::new(0)),
failed: false, done: false,
} }
} }
@ -1028,7 +1028,7 @@ impl<'stmt> Iterator for Rows<'stmt> {
type Item = Result<Row<'stmt>>; type Item = Result<Row<'stmt>>;
fn next(&mut self) -> Option<Result<Row<'stmt>>> { fn next(&mut self) -> Option<Result<Row<'stmt>>> {
if self.failed { if self.done {
return None; return None;
} }
match unsafe { ffi::sqlite3_step(self.stmt.stmt) } { match unsafe { ffi::sqlite3_step(self.stmt.stmt) } {
@ -1041,9 +1041,12 @@ impl<'stmt> Iterator for Rows<'stmt> {
row_idx: current_row, row_idx: current_row,
})) }))
} }
ffi::SQLITE_DONE => None, ffi::SQLITE_DONE => {
self.done = true;
None
}
code => { code => {
self.failed = true; self.done = true;
Some(Err(self.stmt.conn.decode_result(code).unwrap_err())) Some(Err(self.stmt.conn.decode_result(code).unwrap_err()))
} }
} }