Today I installed Safari 4.0, and one of the features which caught my eye is its local database support. No, it’s not new, but perhaps has not received the attention it deserves. The feature lets you use a local SQLite database from JavaScript, both online and offline, and works on the iPhone 2.0 and higher (2.1 for offline support) and in Safari 3.1 and higher. The API is rather simple. windows.openDatabase returns a database object, and you then work with methods like transaction.executeSql, reading the results in a callback function. Security restrictions mean that access to the database is restricted to pages served by the domain from which it was created. Apple has more information in its Safari Client-Side Storage and Offline Applications Programming Guide. Safari’s local database features implement the HTML 5 W3C Web Storage API.
It’s a great feature, and strengthens Safari on the iPhone as an application runtime that avoids the hassles of the App Store. Does it have wider value? A problem is inconsistent support across other browses. Microsoft’s IE8 supports DOM Storage (key-value pairs), which is also part of the HTML 5 standard, but not SQL. FireFox also supports DOM Storage, but its SQLite support is restricted to components and extensions only.
A possible reason for the lack of wider SQL support is that Google has its own implementation in Gears, which works in Safari and FireFox on the Mac, in IE and Firefox on Windows, and in Firefox on Linux. One place you cannot install Gears though is on the iPhone. A possible solution is to create a wrapper API that uses HTML 5 on Safari and Gears elsewhere; Malte Ubl has done some work on this, for example.
Personally I’d like to see the HTML 5.0 specification more widely supported, since along with the iPhone issue, not everyone wants to install Gears. I would have thought it could be added to both Chrome and FireFox relatively easily; but would be interested to know what is planned.