mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-27 03:51:38 +08:00
Implement exists
using query
instead of FFI.
This commit is contained in:
parent
7b174c97f8
commit
493446e6d1
@ -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()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user