A few minor adjustments

This commit is contained in:
Ivan Ukhov 2015-05-29 13:34:48 -04:00
parent ae0a12444b
commit e56b3891bc
3 changed files with 9 additions and 4 deletions

View File

@ -11,7 +11,7 @@ pub struct Database<'l> {
_phantom: PhantomData<&'l raw::sqlite3>, _phantom: PhantomData<&'l raw::sqlite3>,
} }
/// A callback executed for each row of the result of an SQL query. /// A callback triggered for each row of an executed SQL query.
pub type ExecuteCallback<'l> = FnMut(Vec<(String, String)>) -> bool + 'l; pub type ExecuteCallback<'l> = FnMut(Vec<(String, String)>) -> bool + 'l;
impl<'l> Database<'l> { impl<'l> Database<'l> {

View File

@ -109,7 +109,7 @@ mod database;
mod statement; mod statement;
pub use database::{Database, ExecuteCallback}; pub use database::{Database, ExecuteCallback};
pub use statement::{Statement, Binding}; pub use statement::{Statement, Binding, Value};
/// Open a database. /// Open a database.
#[inline] #[inline]

View File

@ -17,25 +17,30 @@ pub enum Binding<'l> {
Text(usize, &'l str), Text(usize, &'l str),
} }
/// A value stored in a column. /// A value stored in a prepared statement.
pub trait Value { pub trait Value {
/// Read the value from a prepared statement at a specific position. /// Read the value at a specific column.
fn read(statement: &mut Statement, i: usize) -> Result<Self>; fn read(statement: &mut Statement, i: usize) -> Result<Self>;
} }
impl<'l> Statement<'l> { impl<'l> Statement<'l> {
/// Assign values to the placeholders. /// Assign values to the placeholders.
///
/// The leftmost parameter has an index of 1.
pub fn bind(&mut self, bindings: &[Binding]) -> Result<()> { pub fn bind(&mut self, bindings: &[Binding]) -> Result<()> {
for binding in bindings.iter() { for binding in bindings.iter() {
match *binding { match *binding {
Binding::Float(i, value) => unsafe { Binding::Float(i, value) => unsafe {
debug_assert!(i > 0, "the indexation starts from 1");
success!(raw::sqlite3_bind_double(self.raw, i as c_int, value as c_double)); success!(raw::sqlite3_bind_double(self.raw, i as c_int, value as c_double));
}, },
Binding::Integer(i, value) => unsafe { Binding::Integer(i, value) => unsafe {
debug_assert!(i > 0, "the indexation starts from 1");
success!(raw::sqlite3_bind_int64(self.raw, i as c_int, success!(raw::sqlite3_bind_int64(self.raw, i as c_int,
value as raw::sqlite3_int64)); value as raw::sqlite3_int64));
}, },
Binding::Text(i, value) => unsafe { Binding::Text(i, value) => unsafe {
debug_assert!(i > 0, "the indexation starts from 1");
success!(raw::sqlite3_bind_text(self.raw, i as c_int, str_to_c_str!(value), success!(raw::sqlite3_bind_text(self.raw, i as c_int, str_to_c_str!(value),
-1, None)); -1, None));
}, },