Skip to content

Instantly share code, notes, and snippets.

@grahamking
Last active December 16, 2015 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamking/5470148 to your computer and use it in GitHub Desktop.
Save grahamking/5470148 to your computer and use it in GitHub Desktop.
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
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