diff --git a/src/database.rs b/src/database.rs index baf77eb..a5dff69 100644 --- a/src/database.rs +++ b/src/database.rs @@ -11,7 +11,7 @@ pub struct Database<'l> { _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; impl<'l> Database<'l> { diff --git a/src/lib.rs b/src/lib.rs index 8433da4..d2f6cd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,7 +109,7 @@ mod database; mod statement; pub use database::{Database, ExecuteCallback}; -pub use statement::{Statement, Binding}; +pub use statement::{Statement, Binding, Value}; /// Open a database. #[inline] diff --git a/src/statement.rs b/src/statement.rs index f30358b..afd4d84 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -17,25 +17,30 @@ pub enum Binding<'l> { Text(usize, &'l str), } -/// A value stored in a column. +/// A value stored in a prepared statement. 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; } impl<'l> Statement<'l> { /// Assign values to the placeholders. + /// + /// The leftmost parameter has an index of 1. pub fn bind(&mut self, bindings: &[Binding]) -> Result<()> { for binding in bindings.iter() { match *binding { 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)); }, 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, value as raw::sqlite3_int64)); }, 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), -1, None)); },