开发者

HTML5: Can an SQlite database be specified in a manifest's Cache section?

I'd like to be able to specify an SQLite database as a resource in the CACHE section of a manifest file. This would allow the script on the page to use the database in offline mode.

I cannot find anything in the HTML5 spec that says this cannot be done, but I haven't had any suc开发者_StackOverflow社区cess in getting it working either.

Is it possible?


Looking at the W3C Offline Web Application spec (http://www.w3.org/TR/html5/offline.html) there doesn't appear to be a way to include SQLite database files in the manifest. Otherwise it looks like it will take just about anything that has a known path relative to the root of the web site. Database files are created by the browser in a separate directory specific to the web site, and the path is different for different browsers. My solution was to create and download the database the first time the application is called - it would be much better to be able to download the file, but I don't see a way to do that.


I played around with it for a while. Here is what I found:

The (web kit) browser uses a database to organize the Web SQL databases. :-)

For chrome it is in (Mac OS X):

~/Library/Application Support/Google/Chrome/Default/databases/Databases.db

You can access this via SQLite3 Databases.db:

Mine looks like:

sqlite> select * from databases;
1|http_slides.html5rocks.com_0|DBTest|HTML5 Database API example|200000
2|http_www.html5rocks.com_0|modernizrtestdb|modernizrtestdb|20000
3|http_www.html5rocks.com_0|Todo|Todo manager|5242880
4|http_experimenting.in_0|mystorage|Web SQL Storage Demo Database|1048576
5|file__0|mystorage|Web SQL Storage Demo Database|1048576
sqlite> .quit

The file ./file__0/5 contains the database for mystorage.

The entries are created when the code does the opendatabase.

I didn't find a way how to create an entry in this database and give it a path or filename.


It's not possible.

Instead, convert your database to a JSON object and write it to a file. Include that file in your manifest. At the other end, read the JSON object in and create the database.

Works well!


I also found a free tool that says it solves this problem - haven't had time to try it yet, but it sounds like it should do the job: http://impel.simulacre.org/blog/incrementally_synchronize_html5_databases_transparently.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜