Make a cosmetic adjustment

This commit is contained in:
Ivan Ukhov 2018-10-06 10:15:11 +02:00
parent 8ddb310ed8
commit 73fb4b7920
2 changed files with 27 additions and 27 deletions

View File

@ -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

View File

@ -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:");