1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| var xhr = new XMLHttpRequest();
xhr.open('GET', 'mabase.db', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
var uInt8Array = new Uint8Array(this.response);
var db = new SQL.Database(uInt8Array);
var contents = db.run("ma requête UPDATE");
console.log(contents);
var arraybuff = db.export();
console.log(arraybuff);
var blob = new Blob([arraybuff]);
whriteInBlob(blob);
db.close();
}
xhr.send();
}
function whriteInBlob (blob) {
// To access the sandboxed file system (meaning two or more apps canât access each others files) you need to initialize the FileSystem object:
if('webkitRequestFileSystem' in window)
{
window.requestFileSystem = window.webkitRequestFileSystem;
window.requestFileSystem(window.PERSISTENT, 10*1024*1024, onSuccess, onError);
}else if('moz_requestFileSystem' in window)
{
//firefox
window.requestFileSystem = window.moz_requestFileSystem;
window.requestFileSystem(window.PERSISTENT, 10*1024*1024, onSuccess, onError);
}
function onSuccess(fs) {
fs.root.getFile('mabase.db', {create:true}, function(fileEntry){
fileEntry.createWriter(function(f) {
f.onwriteend = function(event) {};
f.onerror = function(err) {};
writer.append(blob);
f.write(writer.getBlob('text/plain'));
})
})
} |
Partager