Factorize code

This commit is contained in:
Gwenael Treguier 2015-08-04 18:52:57 +02:00
parent e8967388e6
commit 8bb624cccc

View File

@ -614,14 +614,7 @@ impl<'conn> SqliteStatement<'conn> {
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());
for (i, p) in params.iter().enumerate() {
try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int)));
}
try!(self.bind_parameters(params));
self.needs_reset = true;
let r = ffi::sqlite3_step(self.stmt);
@ -660,11 +653,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.
@ -698,8 +692,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(())
}