title: HTML 5 Web SQL Database Transaction commit or rollback when refreshing page
body: <p>As written in the <a href="http://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html#//apple_ref/doc/uid/TP40007256-CH3-SW3" rel="nofollow">Safari Client-Side Storage and Offline Applications Programming Guide</a>, rolling back a HTML 5 Web SQL Database transaction is done by returning true in the callback function provided as an error callback to <strike>a transaction</strike> the <code>executeSql</code> method:</p>
  
  <blockquote>
    <p>The per-query error-handling callback
    is rather straightforward. If the
    callback returns true, the entire
    transaction is rolled back. If the
    callback returns false, the
    transaction continues as if nothing
    had gone wrong. Thus, if you are
    executing a query that is optional—if
    a failure of that particular query
    should not cause the transaction to
    fail—you should pass in a callback
    that returns false. If a failure of
    the query should cause the entire
    transaction to fail, you should pass
    in a callback that returns true.</p>
  </blockquote>
  
  <p>For example if I have the following transaction (suppose the 'users' table has a UNIQUE constraint on the 'username' field and username 'test' already exists - which I'm trying to insert again, which should result in a constraint error):</p>
  
  <pre><code>database.transaction(function(transaction) {
      transaction.executeSql(
          "INSERT INTO users (username) VALUES('test')",
          null,
          dataCallback,
          errorCallback
       );
  });
  
  function errorCallback() {
      return true; //this causes the rollback
  }
  </code></pre>
  
  <p>I have two questions:</p>
  
  <ol>
  <li><p>If I have to include many operations inside a transaction (for example I have to send some data using ajax to a server and wait for the response, etc.) and the user reloads the page before the response had arrived (which means that the errorCallback won't be called), will the transaction be commited or will it fail ?</p></li>
  <li><p>Does anyone know how to rollback a Web SQL transaction manually ? For example if I want to rollback a transaction based on the result of an ajax call, how can it be done ? Should I run a query which contains an error to make sure that the error callback is called ?</p></li>
  </ol>
  
  <p>Thanks.</p>