1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

fiddle: initial work on loading a client-side db file. Works but requires some cleanup. Export is not yet implemented.

FossilOrigin-Name: 0fa8378c006fcf2311772d36cf2e3c2cd8e8648f671de89ee9832e2e1a06ef49
This commit is contained in:
stephan
2022-05-24 19:01:21 +00:00
parent 6af03b469e
commit de1e02ee52
7 changed files with 173 additions and 39 deletions

View File

@@ -218,6 +218,8 @@
if(sql) SF.dbExec(sql);
},false);
const btnInterrupt = E("#btn-interrupt");
btnInterrupt.classList.add('hidden');
/** To be called immediately before work is sent to the
worker. Updates some UI elements. The 'working'/'end'
event will apply the inverse, undoing the bits this
@@ -237,6 +239,7 @@
}
f._.pageTitle.innerText = "[working...] "+f._.pageTitleOrig;
btnShellExec.setAttribute('disabled','disabled');
btnInterrupt.removeAttribute('disabled','disabled');
};
/* Sends the given text to the db module to evaluate as if it
@@ -258,6 +261,7 @@
preStartWork._.pageTitle.innerText = preStartWork._.pageTitleOrig;
btnShellExec.innerText = preStartWork._.btnLabel;
btnShellExec.removeAttribute('disabled');
btnInterrupt.setAttribute('disabled','disabled');
return;
}
console.warn("Unhandled 'working' event:",ev.data);
@@ -294,12 +298,47 @@
}, false);
});
/* For each button with data-cmd=X, map a click handler which
calls dbExec(X). */
calls SF.dbExec(X). */
const cmdClick = function(){SF.dbExec(this.dataset.cmd);};
EAll('button[data-cmd]').forEach(
e => e.addEventListener('click', cmdClick, false)
);
btnInterrupt.addEventListener('click',function(){
SF.wMsg('interrupt');
});
const fileSelector = E('#load-db');
fileSelector.addEventListener('change',function(){
const f = this.files[0];
const r = new FileReader();
const status = {loaded: 0, total: 0};
fileSelector.setAttribute('disabled','disabled');
r.addEventListener('loadstart', function(){
SF.echo("Loading",f.name,"...");
});
r.addEventListener('progress', function(ev){
SF.echo("Loading progress:",ev.loaded,"of",ev.total,"bytes.");
});
r.addEventListener('load', function(){
fileSelector.removeAttribute('disabled');
SF.echo("Loaded",f.name+". Opening db...");
SF.wMsg('open',{
filename: f.name,
buffer: this.result
});
});
r.addEventListener('error',function(){
fileSelector.removeAttribute('disabled');
SF.echo("Loading",f.name,"failed for unknown reason.");
});
r.addEventListener('abort',function(){
fileSelector.removeAttribute('disabled');
SF.echo("Cancelled loading of",f.name+".");
});
r.readAsArrayBuffer(f);
});
/**
Given a DOM element, this routine measures its "effective
height", which is the bounding top/bottom range of this element
@@ -445,7 +484,7 @@ SELECT group_concat(rtrim(t),x'0a') as Mandelbrot FROM a;`}
taInput.value = '-- ' +
this.selectedOptions[0].innerText +
'\n' + this.value;
//dbExec(this.value);
SF.dbExec(this.value);
});
})()/* example queries */;