1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +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

@@ -253,17 +253,39 @@
};
/**
The DB class wraps a sqlite3 db handle.
The DB class wraps a sqlite3 db handle. Its argument may either
be a db name or a Uint8Array containing a binary image of a
database. If the name is not provided or is an empty string,
":memory:" is used. A string name other than ":memory:" or ""
will currently fail to open, for lack of a filesystem to
load it from. If given a blob, a random name is generated.
Achtung: all arguments other than those specifying an
in-memory db are currently untested for lack of an app
to test them in.
*/
const DB = function(name/*TODO: openMode flags*/){
if(!name) name = ':memory:';
else if('string'!==typeof name){
const DB = function(name/*TODO? openMode flags*/){
let fn, buff;
if(name instanceof Uint8Array){
buff = name;
name = undefined;
fn = "db-"+((Math.random() * 10000000) | 0)+
"-"+((Math.random() * 10000000) | 0)+".sqlite3";
}else if(":memory:" === name || "" === name){
fn = name || ":memory:";
name = undefined;
}else if('string'!==typeof name){
toss("TODO: support blob image of db here.");
}else{
fn = name;
}
if(buff){
FS.createDataFile("/", fn, buff, true, true);
}
setValue(pPtrArg, 0, "i32");
this.checkRc(api.sqlite3_open(name, pPtrArg));
this.checkRc(api.sqlite3_open(fn, pPtrArg));
this._pDb = getValue(pPtrArg, "i32");
this.filename = name;
this.filename = fn;
this._statements = {/*map of open Stmt _pointers_ to Stmt*/};
this._udfs = {/*map of UDF names to wasm function _pointers_*/};
};