diff --git a/src/lib.rs b/src/lib.rs index aa901c8..a036262 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ macro_rules! raise( macro_rules! error( ($connection:expr, $code:expr) => (match ::error::last($connection) { Some(error) => return Err(error), - None => return Err(::Error::from(::ErrorKind::from($code as isize))), + _ => return Err(::Error::from(::ErrorKind::from($code as isize))), }); ); diff --git a/src/statement.rs b/src/statement.rs index f9e7b74..a2e4799 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -36,6 +36,12 @@ pub trait Value { } impl<'l> Statement<'l> { + /// Return the number of columns. + #[inline] + pub fn columns(&mut self) -> usize { + unsafe { ffi::sqlite3_column_count(self.raw.0) as usize } + } + /// Bind the parameter at a specific location. /// /// The leftmost location has the index 1. diff --git a/tests/lib.rs b/tests/lib.rs index 67fabb2..97628ba 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -21,6 +21,7 @@ fn workflow() { { let sql = "INSERT INTO `users` (id, name, age) VALUES (?, ?, ?)"; let mut statement = ok!(connection.prepare(sql)); + assert_eq!(statement.columns(), 0); ok!(statement.bind(1, 1i64)); ok!(statement.bind(2, "Alice")); ok!(statement.bind(3, 20.99)); @@ -44,6 +45,7 @@ fn workflow() { { let sql = "SELECT * FROM `users`"; let mut statement = ok!(connection.prepare(sql)); + assert_eq!(statement.columns(), 3); assert_eq!(ok!(statement.step()), State::Row); assert_eq!(ok!(statement.read::(0)), 1); assert_eq!(ok!(statement.read::(1)), String::from("Alice"));