HTML and CSS Reference
In-Depth Information
// bind the click handlers for the radio buttons
¬ [type=radio]'), function (el) {
el.onclick = function () {
// go!
Creating transactions—
and what they're good for
I've skipped over transactions so far. They're more than meets the
eye. They're not just the way to run queries; they serve a particu-
larly useful purpose. Transactions are like closed environments
in which you can run your queries. You can run just one query
or a group of queries within a transaction. In fact, you can't run
a query without being inside a transaction, since the executeSql
method is only available from the SQLTransaction object.
Possibly the most important aspect of transactions is this: If
something fails inside the transaction (vanilla code or SQL state-
ments), then the whole transaction (including any insertion,
modifications, or deletions) is rolled back. This means it's as if
the whole transaction block of code never happened.
The transaction method takes two arguments. The first is the
content of the transaction; the second, optional, is the error
handler. Below is a contrived example that shows how a failed
transaction gets rolled back:
var db = openDatabase('foo', '1.0', 'foo', 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE foo (id unique, text)');
Search WWH ::

Custom Search