1

I have the following javascript function:

function initDatabase() {

    if (!window.openDatabase) {
        alert('Databases not supported in this browser');
    } else {
        var shortName = 'TestDB';
        var version = '1.0';
        var displayName = 'HTML5 Test Database';
        var maxSize = 1024 * 1024;
        db = openDatabase(shortName, version, displayName, maxSize);
        alert('opened db ' + db); //this says its a database

        db.transaction(function (tx) {
            alert('before create'); //never gets here
            tx.executeSql('CREATE TABLE IF NOT EXISTS Person(FirstName TEXT, MiddleName TEXT, LastName TEXT);');
            alert('after create');
        });

        alert('after transaction'); //does get here
    }
}

being called on document ready:

 $(document).ready(function () {
        initDatabase();
    });

As you can see from the comments, the database appears to be created/opened (not sure how I can verify this though) but when I attempt create a transaction and execute some sql, the function never seems to be entered.

Am I doing something wrong? How can I verify that the database even exists?

I am using Chrome 14 for testing.

Thanks

1
  • A possibility would be to write var db = openDatabase(... instead of db = openDatabase(.... Commented Oct 27, 2011 at 16:34

1 Answer 1

2

The alert seems to be the caveat. It might be suspending things causing it not to work.

alert is "superseded" by console.log anyway (in terms of debugging), and if I replace the alerts with logs, everything seems to work (I get all four logs).

(To view these console.log calls, you can press F12 and click on Console.)

Sign up to request clarification or add additional context in comments.

1 Comment

Well that just makes me feel foolish. Thanks for the information. Everything seems to be working just fine without the alerts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.