· 9 years ago · Jan 30, 2017, 05:20 AM
1// create a new database
2// openDatabase(id,version,name,size)
3var db = openDatabase("notes", "", "The Example Notes App!", 1048576);
4
5// open transction
6// db.transaction expects a function with a transaction argument in which the unit of work will be processed
7db.transaction(function(tx) {
8
9// if notes table does not exist create it
10// transaction.executeSql(sqlString,arguments[,successCallback,errorCallback]);
11 tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(id INTEGER primary key, title TEXT, body TEXT)',
12 []);
13// select all data from notes
14 tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
15// iterate on the results and log them to the console
16 for(var i = 0; i < rs.rows.length; i++) {
17 console.log(JSON.stringify(rs.rows.item(i)));
18 }
19 });
20});