From 4fa6d3c020734d442c26411564f66ffe03155cf4 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 1 Aug 2015 10:18:06 +0200 Subject: [PATCH] Reset as soon as possible. --- src/lib.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0435cb3..ecab5f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -613,20 +613,11 @@ impl<'conn> SqliteStatement<'conn> { /// } /// ``` pub fn execute(&mut self, params: &[&ToSql]) -> SqliteResult { - self.reset_if_needed(); - unsafe { - assert!(params.len() as c_int == ffi::sqlite3_bind_parameter_count(self.stmt), - "incorrect number of parameters to execute(): expected {}, got {}", - ffi::sqlite3_bind_parameter_count(self.stmt), - params.len()); + try!(self.bind_parameters(params)); - for (i, p) in params.iter().enumerate() { - try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); - } - - self.needs_reset = true; let r = ffi::sqlite3_step(self.stmt); + ffi::sqlite3_reset(self.stmt); match r { ffi::SQLITE_DONE => { if self.column_count != 0 { @@ -669,11 +660,12 @@ impl<'conn> SqliteStatement<'conn> { try!(self.bind_parameters(params)); } + self.needs_reset = true; Ok(SqliteRows::new(self)) } /// Executes the prepared statement and maps a function over the resulting - /// rows. + /// rows. /// /// Unlike the iterator produced by `query`, the returned iterator does not expose the possibility /// for accessing stale rows. @@ -707,8 +699,6 @@ impl<'conn> SqliteStatement<'conn> { try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); } - self.needs_reset = true; - Ok(()) }