Reputation: 1913
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
Upvotes: 1
Views: 950
Reputation: 154838
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.)
Upvotes: 2