diff --git a/src/statement.rs b/src/statement.rs index d2995e8..073baa2 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -55,6 +55,20 @@ impl<'l> Statement<'l> { unsafe { ffi::sqlite3_column_count(self.raw.0) as usize } } + /// Return the type of a column. + /// + /// The type is revealed after the first step has been taken. + pub fn kind(&self, i: usize) -> Type { + match unsafe { ffi::sqlite3_column_type(self.raw.0, i as c_int) } { + ffi::SQLITE_BLOB => Type::Binary, + ffi::SQLITE_FLOAT => Type::Float, + ffi::SQLITE_INTEGER => Type::Integer, + ffi::SQLITE_TEXT => Type::String, + ffi::SQLITE_NULL => Type::Null, + _ => unreachable!(), + } + } + /// Return the name of a column. #[inline] pub fn name(&self, i: usize) -> &str { @@ -71,20 +85,6 @@ impl<'l> Statement<'l> { (0..self.count()).map(|i| self.name(i)).collect() } - /// Return the type of a column. - /// - /// The type is revealed after the first step has been taken. - pub fn kind(&self, i: usize) -> Type { - match unsafe { ffi::sqlite3_column_type(self.raw.0, i as c_int) } { - ffi::SQLITE_BLOB => Type::Binary, - ffi::SQLITE_FLOAT => Type::Float, - ffi::SQLITE_INTEGER => Type::Integer, - ffi::SQLITE_TEXT => Type::String, - ffi::SQLITE_NULL => Type::Null, - _ => unreachable!(), - } - } - /// Advance to the next state. /// /// The function should be called multiple times until `State::Done` is diff --git a/tests/lib.rs b/tests/lib.rs index 10a00bd..fc647fe 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -134,6 +134,19 @@ fn cursor_workflow() { assert_eq!(ok!(select.next()), None); } +#[test] +fn statement_bind() { + let connection = setup_users(":memory:"); + let statement = "INSERT INTO users (id, name, age, photo) VALUES (?, ?, ?, ?)"; + let mut statement = ok!(connection.prepare(statement)); + + ok!(statement.bind(1, 2i64)); + ok!(statement.bind(2, "Bob")); + ok!(statement.bind(3, 69.42)); + ok!(statement.bind(4, &[0x69u8, 0x42u8][..])); + assert_eq!(ok!(statement.next()), State::Done); +} + #[test] fn statement_count() { let connection = setup_users(":memory:"); @@ -175,19 +188,6 @@ fn statement_kind() { assert_eq!(statement.kind(3), Type::Binary); } -#[test] -fn statement_bind() { - let connection = setup_users(":memory:"); - let statement = "INSERT INTO users (id, name, age, photo) VALUES (?, ?, ?, ?)"; - let mut statement = ok!(connection.prepare(statement)); - - ok!(statement.bind(1, 2i64)); - ok!(statement.bind(2, "Bob")); - ok!(statement.bind(3, 69.42)); - ok!(statement.bind(4, &[0x69u8, 0x42u8][..])); - assert_eq!(ok!(statement.next()), State::Done); -} - #[test] fn statement_read() { let connection = setup_users(":memory:");