Implement exists using query instead of FFI.

This commit is contained in:
John Gallagher 2016-05-16 11:18:15 -05:00
parent 7b174c97f8
commit 493446e6d1

View File

@ -1,5 +1,3 @@
use super::ffi;
use {Error, Result, Statement}; use {Error, Result, Statement};
use types::ToSql; use types::ToSql;
@ -26,15 +24,10 @@ impl<'conn> Statement<'conn> {
/// and `false` if the SQL returns an empty set. /// and `false` if the SQL returns an empty set.
pub fn exists(&mut self, params: &[&ToSql]) -> Result<bool> { pub fn exists(&mut self, params: &[&ToSql]) -> Result<bool> {
self.reset_if_needed(); self.reset_if_needed();
unsafe { let mut rows = try!(self.query(params));
try!(self.bind_parameters(params)); match rows.next() {
let r = ffi::sqlite3_step(self.stmt); Some(_) => Ok(true),
ffi::sqlite3_reset(self.stmt); None => Ok(false),
match r {
ffi::SQLITE_DONE => Ok(false),
ffi::SQLITE_ROW => Ok(true),
_ => Err(self.conn.decode_result(r).unwrap_err()),
}
} }
} }
} }