Created
April 26, 2014 16:13
-
-
Save nolanlawson/11324065 to your computer and use it in GitHub Desktop.
websql_example.js
This file contains 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
openDatabase('mydatabase', 1, 'mydatabase', 5000000, function (db) { | |
function onTransactionSuccess() { | |
console.log('yay, transaction succeeded!'); | |
} | |
function onTransactionError() { | |
console.log('boo, transaction failed!'); | |
} | |
db.transaction(function (tx) { | |
tx.executeSql('CREATE TABLE rainstorms (mood TEXT NOT NULL PRIMARY KEY, severity INTEGER);', [], function () { | |
tx.executeSql('INSERT INTO rainstorms VALUES (?, ?)', ['somber', 6], function () { | |
tx.executeSql('SELECT * FROM rainstorms WHERE mood = ?', ['somber'], function (tx, res) { | |
var row = res.rows.item(0); | |
console.log('rainstorm was a ' + row.severity + ', I felt ' + row.mood); | |
}) | |
}); | |
}); | |
}, onTransactionError, onTransactionSuccess); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment