Skip to content

Instantly share code, notes, and snippets.

@grahamking grahamking/use_sqlite.rs
Last active Dec 16, 2015

Embed
What would you like to do?
Rust: Use sqlite
extern mod sqlite;
fn db() {
let database =
match sqlite::open("test.db") {
Ok(db) => db,
Err(e) => {
println(fmt!("Error opening test.db: %?", e));
return;
}
};
let mut result = database.exec("CREATE TABLE test (name text, age int)");
println(fmt!("Create OK? %?", result.is_ok()));
result = database.exec("INSERT INTO test VALUES ('Graham', 36)");
println(fmt!("Insert OK? %?", result.is_ok()));
}
fn main() {
db();
}
@rofrol

This comment has been minimized.

Copy link

rofrol commented Nov 18, 2013

extern mod sqlite;

fn db() {

let database =
    match sqlite::open("test.db") {
        Ok(db) => db,
        Err(e) => {
            println(format!("Error opening test.db: {:?}", e));
            return;
        }
    };
let mut result = database.exec("CREATE TABLE test (name text, age int)");
println(format!("Create OK? {:?}", result.is_ok()));

result = database.exec("INSERT INTO test VALUES ('Graham', 36)");
println(format!("Insert OK? {:?}", result.is_ok()));

}

fn main() {
db();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.