Skip to content

Instantly share code, notes, and snippets.

@codeinvain
Created June 21, 2010 16:17
Show Gist options
  • Save codeinvain/447088 to your computer and use it in GitHub Desktop.
Save codeinvain/447088 to your computer and use it in GitHub Desktop.
// create a new database
// openDatabase(id,version,name,size)
var db = openDatabase("notes", "", "The Example Notes App!", 1048576);
// open transction
// db.transaction expects a function with a transaction argument in which the unit of work will be processed
db.transaction(function(tx) {
// if notes table does not exist create it
// transaction.executeSql(sqlString,arguments[,successCallback,errorCallback]);
tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(id INTEGER primary key, title TEXT, body TEXT)',
[]);
// select all data from notes
tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
// iterate on the results and log them to the console
for(var i = 0; i < rs.rows.length; i++) {
console.log(JSON.stringify(rs.rows.item(i)));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment