mirror of
https://github.com/isar/rusqlite.git
synced 2025-12-08 12:32:24 +08:00
Extract RawStatement wrapper around *mut sqlite3_stmt.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use libc::c_int;
|
||||
|
||||
use super::ffi;
|
||||
|
||||
use {Result, Error, Connection, Statement, Rows, Row, str_to_cstring};
|
||||
use types::ToSql;
|
||||
|
||||
@@ -56,11 +54,7 @@ impl<'conn> Statement<'conn> {
|
||||
/// is valid but not a bound parameter of this statement.
|
||||
pub fn parameter_index(&self, name: &str) -> Result<Option<i32>> {
|
||||
let c_name = try!(str_to_cstring(name));
|
||||
let c_index = unsafe { ffi::sqlite3_bind_parameter_index(self.stmt, c_name.as_ptr()) };
|
||||
Ok(match c_index {
|
||||
0 => None, // A zero is returned if no matching parameter is found.
|
||||
n => Some(n),
|
||||
})
|
||||
Ok(self.stmt.bind_parameter_index(&c_name))
|
||||
}
|
||||
|
||||
/// Execute the prepared statement with named parameter(s). If any parameters
|
||||
@@ -87,7 +81,7 @@ impl<'conn> Statement<'conn> {
|
||||
/// which case `query` should be used instead), or the underling SQLite call fails.
|
||||
pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result<c_int> {
|
||||
try!(self.bind_parameters_named(params));
|
||||
unsafe { self.execute_() }
|
||||
self.execute_()
|
||||
}
|
||||
|
||||
/// Execute the prepared statement with named parameter(s), returning an iterator over the
|
||||
@@ -120,7 +114,7 @@ impl<'conn> Statement<'conn> {
|
||||
fn bind_parameters_named(&mut self, params: &[(&str, &ToSql)]) -> Result<()> {
|
||||
for &(name, value) in params {
|
||||
if let Some(i) = try!(self.parameter_index(name)) {
|
||||
try!(self.conn.decode_result(unsafe { value.bind_parameter(self.stmt, i) }));
|
||||
try!(self.conn.decode_result(unsafe { value.bind_parameter(self.stmt.ptr(), i) }));
|
||||
} else {
|
||||
return Err(Error::InvalidParameterName(name.into()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user