views:

48

answers:

1

Hello,

I have a site that is fully functioning in Chrome/Safari and heavily relied on SQLite to store/access data. However, when testing in Firefox, it errors on the first call, openDatabase(). This is my fairly standard openDB function:

function openDB(){
try {
    if (!window.openDatabase) {
        alert('not supported');
    } else {
        var shortName = 'tales';
        var version = '1.0';
        var displayName = 'Tall Tales Database';
        var maxSize = 65536; // in bytes
        db = openDatabase(shortName, version, displayName, maxSize); 
        // You should have a database instance in db.
    }
} catch(e) {
    // Error handling code goes here.
    if (e == 2) {
        // Version number mismatch.
        alert("Invalid database version.");
    } else {
        alert("Unknown error "+e+".");
    }
    return;
}

}

Like I said - openDatabase is undefined when I alert it, and the Unknown error that prints is "unsupported". I assume SQLite is actually supported in Firefox, am I doing something wrong or does it require browser-specific code?

Thank you! Claudia

+1  A: 

Firefox doesn't have that feature. Mozilla doesn't think SQLite is appropriate for the web, so in Firefox 4 they will be instead opting for and implementing the IndexedDB spec. draft by the W3C (incl. proposals by Mozilla). Here's a nice blog post detailing the differences: http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/

So yes, you will have to use client specific code in order to support FF4 - at least until IndexedDB is implemented in the other major browsers. For anything before FF4, there is no support for any client database (not counting localStorage, etc.).

CD Sanchez
It's not "their own database API" though. It is also a W3C standard, and IndexedDB is being actively worked on and implemented by Mozilla, Chromium, and Microsoft.
sdwilsh
@sdwilsh: Well what I meant is that Mozilla made large contributions to the asynchronous API specifically. It's their own API in the sense that they thought it up and designed it. I edited my post anyways as to make it clearer that it is not a "closed" solution -- that is, that they are actively trying to the specification to its final state for use by all. Thank you for pointing that out though.
CD Sanchez