Introduce Type and Statement::kind for reading it

This commit is contained in:
Ivan Ukhov
2015-08-01 16:23:05 -04:00
parent e73c9cd508
commit ea9eff2fd2
5 changed files with 147 additions and 92 deletions

View File

@ -6,11 +6,11 @@
//! let connection = sqlite::open(":memory:").unwrap();
//!
//! connection.execute("
//! CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
//! INSERT INTO `users` (id, name) VALUES (42, 'Alice');
//! CREATE TABLE users (id INTEGER, name VARCHAR(255));
//! INSERT INTO users (id, name) VALUES (42, 'Alice');
//! ").unwrap();
//!
//! connection.process("SELECT * FROM `users`", |pairs| {
//! connection.process("SELECT * FROM users", |pairs| {
//! for &(column, value) in pairs.iter() {
//! println!("{} = {}", column, value.unwrap());
//! }
@ -26,17 +26,17 @@
//! let connection = sqlite::open(":memory:").unwrap();
//!
//! connection.execute("
//! CREATE TABLE `users` (id INTEGER, name VARCHAR(255))
//! CREATE TABLE users (id INTEGER, name VARCHAR(255))
//! ");
//!
//! let mut statement = connection.prepare("
//! INSERT INTO `users` (id, name) VALUES (?, ?)
//! INSERT INTO users (id, name) VALUES (?, ?)
//! ").unwrap();
//! statement.bind(1, 42).unwrap();
//! statement.bind(2, "Alice").unwrap();
//! assert_eq!(statement.step().unwrap(), State::Done);
//!
//! let mut statement = connection.prepare("SELECT * FROM `users`").unwrap();
//! let mut statement = connection.prepare("SELECT * FROM users").unwrap();
//! while let State::Row = statement.step().unwrap() {
//! println!("id = {}", statement.read::<i64>(0).unwrap());
//! println!("name = {}", statement.read::<String>(1).unwrap());
@ -98,6 +98,21 @@ macro_rules! str_to_cstr(
});
);
/// A data type.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Type {
/// Binary data.
Blob,
/// A 64-bit IEEE floating-point number.
Float,
/// A 64-bit signed integer.
Integer,
/// An absence of a value.
Null,
/// A string.
String,
}
mod connection;
mod error;
mod statement;