Skip to content

Instantly share code, notes, and snippets.

@brinchj
Created November 7, 2013 22:35
Show Gist options
  • Save brinchj/7363049 to your computer and use it in GitHub Desktop.
Save brinchj/7363049 to your computer and use it in GitHub Desktop.
extern mod sqlite;
use sqlite::types::SQLITE_OK;
fn open_db(path: ~str) -> sqlite::database::Database {
match sqlite::open(path) {
Ok(db) => db,
Err(r) => fail!(r)
}
}
fn test() {
let mut db = open_db(~":memory:");
// Create table
let result = db.exec("CREATE TABLE IF NOT EXISTS test (name text)");
println(format!("Create OK? {:b}", result.is_ok()));
// Prepared insert
let mut stmt = match db.prepare("INSERT INTO test (name) VALUES (?)", &None) {
Ok(s) => s,
Err(err) => fail!(err)
};
assert!(stmt.bind_param(1, &sqlite::types::Text(~"test")) == SQLITE_OK);
}
fn main() {
test()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment