1

I was looking at a greasemonkey script today trying to figure out why it wasn't working any more. After playing around a while I realized it worked fine on firefox 3.6 but not on later versions like the current one (8).

After a bit of googling I landed here.

I'm not sure if I'm reading this correctly. WebSQL is being dropped from Firefox entirely because the standardization process has reached an "impasse", because there is no alternative implementation except for SQLite? Does this mean greasemonkey scripts that rely on WebSQL require ff 3.6 to run properly?

I wonder how hard it might be to simply fork SQLite into NotSQLite and have the standardization process continue...

Community
  • 1
  • 1
Dexter
  • 3,072
  • 5
  • 31
  • 32
  • WebSQL was never supported in Firefox. So if your script worked in 3.6, it's not using WebSQL. – Boris Zbarsky Nov 15 '11 at 01:08
  • Are you sure Boris Zbarsky? This is the script in question: http://userscripts.org/scripts/review/81875 – Dexter Nov 15 '11 at 02:01
  • It looks like [that script](http://userscripts.org/scripts/review/81875) uses `sessionStorage` when running on Firefox. Notice all the `unsafeWindow.sessionStorage...` code in the `else` clauses of the `if (DataStorage.hasLocalSQLiteStorage())` statements?   If it stopped working in later FF versions, something else is likely going on. – Brock Adams Nov 15 '11 at 02:37
  • @Dexter Very sure. There is no openDatabase on Window objects in Firefox 3.6. See for yourself: http://mxr.mozilla.org/mozilla1.9.2/search?string=opendatabase&find=idl&findi=&filter=^[^\0]*%24&hitlimit=&tree=mozilla1.9.2 Now that script, as Brock says, falls back to sessionStorage if there is no WebSQL support. I have no idea why that fallback is not working for you. – Boris Zbarsky Nov 15 '11 at 04:49

3 Answers3

5

Firefox didn't axe WebSQL by themselves; the W3C has declared it dead.

Note that Firefox still uses SQLite, which is not the same as WebSQL. However, a Greasemonkey script does not have direct access to SQLite directly.

You can use sessionStorage, localStorage, and/or globalStorage to persist values.

Or you can use IndexedDB which is the replacement for WebSQL.

Finally, for full-on SQL capabilities, there is the old standard of AJAXing data back and forth to your own server.

Obviously, it's not a good idea to remain on FF 3.6, due to lack of ongoing support, and increasing certainty of security exploits.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 1
    Thanks for your comment. Since there seems to be no way around a major rewrite I'll probably be opting for chrome anyways. This sort of puts the final nail in Mozilla's coffin for me. – Dexter Nov 15 '11 at 01:59
  • 1
    I think I remember reading somewhere that Chrome was going to drop support for WebSQL in about a year. But I don't have a link at the moment. – Brock Adams Nov 15 '11 at 02:09
3

You might be interested in noting that there is a new option for SQLite in Firefox - SQL.js. This is a JavaScript library that was created using Emscripten to translate the original C code into runnable JavaScript. You can load the entire SQLite environment into Firefox (or Chrome or Safari or IE10) and create a new database within memory. If you need to persist things, that might be a bit tricky, but you could probably write your data out to localStorage as needed.

If you'd like to see this code in action, you can check it out here: http://sqlfiddle.com/#!5/781d4/2

And if you'd like to compare it with WebSQL, you can do that at SQL Fiddle too: http://sqlfiddle.com/#!7/04eca/1 (obviously only for browsers which support WebSQL).

Full disclosure - sqlfiddle.com is my site. You may be interested in some of the interface code I wrote for SQL.js though - see it here: https://github.com/jakefeasel/sqlfiddle/blob/master/javascripts/sqljs_driver.js

Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
0

I'm a bit late to the party, but in case anyone else stumbles across this question I've created an add-on for Firefox to use the built-in SQLite support to prove WebSQL functions https://addons.mozilla.org/en-US/firefox/addon/html5-websql-for-firefox/

EionRobb
  • 532
  • 5
  • 13