mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-04-25 08:42:14 +00:00
Add Statement::columns
This commit is contained in:
parent
2275f8157f
commit
3d0bf10912
@ -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))),
|
||||
});
|
||||
);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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::<i64>(0)), 1);
|
||||
assert_eq!(ok!(statement.read::<String>(1)), String::from("Alice"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user