mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-29 21:52:12 +08:00
Fuse a Rows
iterator once it fetches the final row.
This commit is contained in:
parent
4a6c7b5329
commit
8e1ce5cf9c
13
src/lib.rs
13
src/lib.rs
@ -1004,7 +1004,7 @@ pub type SqliteRows<'stmt> = Rows<'stmt>;
|
||||
pub struct Rows<'stmt> {
|
||||
stmt: &'stmt Statement<'stmt>,
|
||||
current_row: Rc<Cell<c_int>>,
|
||||
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<Row<'stmt>>;
|
||||
|
||||
fn next(&mut self) -> Option<Result<Row<'stmt>>> {
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user