Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 13
Registered: ‎10-01-2011
My Device: 9900
My Carrier: MTN

HTML5Database, transaction and alert() - transaction callback not being called


We've run into a strange situation. We're calling a database.transaction(txCallback, txError, txSuccess),
and if we follow the transaction call with an alert() call, the txSuccess function is called without the
txCallback function ever being called.

Is this a known error, or documented behaviour with a reasonable explanation?

This HTML demonstrates the situation well in Ripple Emulator:

    function dbalert() {
      var db = window.openDatabase("test","1.0","test",1024*1024);
      console.log("Next line should read: In transaction callback");
      window.transactionCalled = false;
        function (tx) {
            console.log("In transaction callback");
            window.transactionCalled = true;
        function (tx, err) {
        function () {
            if (window.transactionCalled) {
                console.log("Success callback: everything worked!");
            } else {
                console.error("Success callback: BUT TRANSACTION WAS NEVER CALLED");
       * Change to FALSE to get this working.
      if (true) {
        alert("Ok, let's see what happened");
      } else {
        console.log("Ok, let's see what happened");
    <body onLoad="dbalert();">
    <div id="out">

Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: HTML5Database, transaction and alert() - transaction callback not being called

HTML5 database is asyncronous.  When you introduce the modal alert() dialog box, it forces the main thread to stop and wait, while the DB thread continues its action.  The code you have shown appears to be functioning as it should be - dbalert function being called from the onload event, immediately start a transaction; the alert forces the app to wait and in that time the transaction completes.


FYI: here's another sample page that includes a demo of how to use transactions:


Follow me on Twitter: @n_adam_stanley
Your app doesn't work? Use BlackBerry remote web inspector to find out why.