Minor refactor to avoid needing to expose Statement::decode_result().

This commit is contained in:
John Gallagher 2017-03-08 11:04:22 -05:00
parent 38c9a4a159
commit 723fc91a09
2 changed files with 14 additions and 17 deletions

View File

@ -906,19 +906,17 @@ impl<'stmt> Rows<'stmt> {
/// or `query_and_then` instead, which return types that implement `Iterator`. /// or `query_and_then` instead, which return types that implement `Iterator`.
pub fn next<'a>(&'a mut self) -> Option<Result<Row<'a, 'stmt>>> { pub fn next<'a>(&'a mut self) -> Option<Result<Row<'a, 'stmt>>> {
self.stmt.and_then(|stmt| match stmt.step() { self.stmt.and_then(|stmt| match stmt.step() {
ffi::SQLITE_ROW => { Ok(true) => Some(Ok(Row {
Some(Ok(Row {
stmt: stmt, stmt: stmt,
phantom: PhantomData, phantom: PhantomData,
})) })),
} Ok(false) => {
ffi::SQLITE_DONE => {
self.reset(); self.reset();
None None
} }
code => { Err(err) => {
self.reset(); self.reset();
Some(Err(stmt.decode_result(code).unwrap_err())) Some(Err(err))
} }
}) })
} }

View File

@ -234,9 +234,8 @@ pub trait StatementCrateImpl<'conn> {
fn bind_parameter_index(&self, name: &CStr) -> Option<c_int>; fn bind_parameter_index(&self, name: &CStr) -> Option<c_int>;
fn last_insert_rowid(&self) -> i64; fn last_insert_rowid(&self) -> i64;
fn value_ref(&self, col: c_int) -> ValueRef; fn value_ref(&self, col: c_int) -> ValueRef;
fn step(&self) -> c_int; fn step(&self) -> Result<bool>;
fn reset(&self) -> c_int; fn reset(&self) -> c_int;
fn decode_result(&self, code: c_int) -> Result<()>;
} }
impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
@ -362,15 +361,15 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
} }
} }
fn step(&self) -> i32 { fn step(&self) -> Result<bool> {
self.stmt.step() match self.stmt.step() {
ffi::SQLITE_ROW => Ok(true),
ffi::SQLITE_DONE => Ok(false),
code => Err(self.conn.decode_result(code).unwrap_err()),
}
} }
fn reset(&self) -> c_int { fn reset(&self) -> c_int {
self.stmt.reset() self.stmt.reset()
} }
fn decode_result(&self, code: c_int) -> Result<()> {
self.conn.decode_result(code)
}
} }