Is it possible to download a SQLite database for local use via HTML5 offline?
I am considering creating an HTML5 application that would require downloading a SQLite database from the server and then accessing that database locally to reference the data offline.
Is it possible to download a pre-populated SQLite database and access it locally using HTML5? I haven't been able to find any example or tutorial on this subject.
My current thought was to create the site so that it can be run offline via the manifest cache files (still not a problem) BUT it also needs to have access to a pre-populated SQLite database downloaded from the server and that the part I'm not sure how to handle.
Online, the HTML5 application should be able to check the server for updates, restore the manifest cache again, and update the database ...
source to share
HTML5 and SQLite are not the same thing. The offline storage and web SQL features for HTML5 use implementations with SQLite, but not all implementations will use SQLite.
In this case, the short answer would be: no.
Instead, you should keep your data in sync by doing something like ... storing update timestamps and passing data back and forth using JSON (or similar).
source to share
There is a Web SQL Database Specification that gives a SQL-like interface, but unfortunately it is no longer under active maintenance. However, it is implemented in Chrome, Opera and Safari ( http://en.wikipedia.org/wiki/Web_SQL_Database ). Here is a tutorial on webbases .
A possible alternative if your database is less than 5MB ( http://dev.w3.org/html5/webstorage/#disk-space ) and you can do it with something like dictionary / array / hashmap is using local storage .
So, if your browser supports local storage, the idea is to store your database as a JSON string in local storage (local storage can only store strings) and whenever you need to access the data you download + analyze. You will need the following tools:
// Test if you browser supports local storage
'localStorage' in window && window['localStorage'] !== null;
// Store value in local storage
localStorage.setItem(key, value);
// Load value from local storage
localStorage.getItem(key);
// Parse JSON to JavaScript object
JSON.parse('{"name":"John"}');
// Convert JavaScript object to JSON
JSON.stringify({"name":"John"})
Most modern browsers have JSON support built in. There is a great JSON-js library for older browsers .
source to share