HTML and CSS Reference
In-Depth Information
alert('Rollback triggered, the table “foo” was never
¬ dropped due to: ' + error.message);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM foo', [], function (tx,
¬ results) {
alert('found ' + results.rows.length + ' row');
}, function (tx, error) {
// this will never execute
alert('something went wrong: ' + error.message);
What you're doing in the previous code is:
1. Start a transaction that creates the table foo and then
inserts a single row
2. Start a transaction that drops the table foo and then incor-
rectly tries to insert a new row in foo
3. This transaction will fail, and rollback the statements (that is,
it's as if step 2 never happened)
4. Start a transaction that selects all the rows from foo and
alerts the number of rows
5. The SQL query succeeds and shows “found 1 row”
Transactions are used to ensure an atomic block of queries
execute and if any part fails, it rolls back.
In this chapter, you learned about two different APIs for storing
data locally in the browser that beats the pants off using cook-
ies (and there's more storage specs in the works with Indexed
Database API).
These storage APIs allow you to store a lot more data than the
traditional cookie and make the associated programming a lot
easier than before. On top of which, the Web Storage API has
really good support in all the latest browsers (and older brows-
ers can be supported using JavaScript), so it means you can
drop the awful and stale cookies of today!
Search WWH ::

Custom Search