From 723fc91a09fce16a27d221307709a737f44881d1 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Wed, 8 Mar 2017 11:04:22 -0500 Subject: [PATCH] Minor refactor to avoid needing to expose Statement::decode_result(). --- src/lib.rs | 16 +++++++--------- src/statement.rs | 15 +++++++-------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 92d4f52..6f2ace8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -906,19 +906,17 @@ impl<'stmt> Rows<'stmt> { /// or `query_and_then` instead, which return types that implement `Iterator`. pub fn next<'a>(&'a mut self) -> Option>> { self.stmt.and_then(|stmt| match stmt.step() { - ffi::SQLITE_ROW => { - Some(Ok(Row { - stmt: stmt, - phantom: PhantomData, - })) - } - ffi::SQLITE_DONE => { + Ok(true) => Some(Ok(Row { + stmt: stmt, + phantom: PhantomData, + })), + Ok(false) => { self.reset(); None } - code => { + Err(err) => { self.reset(); - Some(Err(stmt.decode_result(code).unwrap_err())) + Some(Err(err)) } }) } diff --git a/src/statement.rs b/src/statement.rs index 620f924..f64a40c 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -234,9 +234,8 @@ pub trait StatementCrateImpl<'conn> { fn bind_parameter_index(&self, name: &CStr) -> Option; fn last_insert_rowid(&self) -> i64; fn value_ref(&self, col: c_int) -> ValueRef; - fn step(&self) -> c_int; + fn step(&self) -> Result; fn reset(&self) -> c_int; - fn decode_result(&self, code: c_int) -> Result<()>; } impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { @@ -362,15 +361,15 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { } } - fn step(&self) -> i32 { - self.stmt.step() + fn step(&self) -> Result { + 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 { self.stmt.reset() } - - fn decode_result(&self, code: c_int) -> Result<()> { - self.conn.decode_result(code) - } }