Skip to content

Instantly share code, notes, and snippets.

@macdonst
Created December 21, 2011 21:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save macdonst/1507843 to your computer and use it in GitHub Desktop.
Save macdonst/1507843 to your computer and use it in GitHub Desktop.
Create DB from .sql file
if (localStorage.getItem("dbCreated") != true) {
html5sql.openDatabase("ScratchDB", "Scratch DB", 3 * 1024 * 1024);
var request = new XMLHttpRequest();
request.open("GET", "file:///android_asset/www/create.sql", true);
request.onreadystatechange = function(){
if (request.readyState == 4) {
if (request.status == 200 || request.status == 0) {
html5sql.process(request.responseText,
function(){
console.log("Win!");
localStorage.setItem("dbCreated", true);
},
function(error){
console.log("Fail!");
}
);
}
}
}
request.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment