Created
June 21, 2010 16:17
-
-
Save codeinvain/447088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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