diff --git a/src/statement.rs b/src/statement.rs index 28eb39e..4b23978 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -1,10 +1,12 @@ use ffi; -use libc::{c_double, c_int, c_void}; -use std::ffi::CString; +use libc::{c_double, c_int}; use std::marker::PhantomData; use {Cursor, Result, Type, Value}; +// https://sqlite.org/c3ref/c_static.html +macro_rules! transient(() => (::std::mem::transmute(!0 as *const ::libc::c_void))); + /// A prepared statement. pub struct Statement<'l> { raw: (*mut ffi::sqlite3_stmt, *mut ffi::sqlite3), @@ -126,7 +128,8 @@ impl<'l> Bindable for &'l [u8] { unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_blob(statement.raw.0, i as c_int, self.as_ptr() as *const _, - self.len() as c_int, None)); + self.len() as c_int, + transient!())); } Ok(()) } @@ -162,8 +165,9 @@ impl<'l> Bindable for &'l str { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { ok!(statement.raw.1, ffi::sqlite3_bind_text(statement.raw.0, i as c_int, - str_to_cstr!(self).into_raw(), -1, - Some(drop_cstring))); + self.as_ptr() as *const _, + self.len() as c_int, + transient!())); } Ok(()) } @@ -246,7 +250,3 @@ pub fn new<'l, T: AsRef>(raw1: *mut ffi::sqlite3, statement: T) -> Result