mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
shell: in WASM mode, permit ATTACH because the filesystem is a virtual sandbox and ATTACH can be used to provide more import/export options. Minor doc updates in sqlite3-api.js.
FossilOrigin-Name: f28de5b726999b913b442fa51355d020ba1f1662d2f7978380623c16438eb238
This commit is contained in:
@ -222,11 +222,10 @@ Module.postRun.push(function(namespace/*the module object, the target for
|
||||
["sqlite3_prepare_v2", "number", ["number", "string", "number", "number", "number"]],
|
||||
["sqlite3_prepare_v2_sqlptr", "sqlite3_prepare_v2",
|
||||
/* Impl which requires that the 2nd argument be a pointer to
|
||||
the SQL, instead of a string. This is used for cases where
|
||||
we require a non-NULL value for the final argument. We may
|
||||
or may not need this, depending on how our higher-level
|
||||
API shapes up, but this code's spiritual guide (sql.js)
|
||||
uses it we we'll include it. */
|
||||
the SQL string, instead of being converted to a
|
||||
string. This is used for cases where we require a non-NULL
|
||||
value for the final argument (exec()'ing multiple
|
||||
statements from one input string). */
|
||||
"number", ["number", "number", "number", "number", "number"]],
|
||||
["sqlite3_reset", "number", ["number"]],
|
||||
["sqlite3_result_blob",null,["number", "number", "number", "number"]],
|
||||
@ -1518,6 +1517,29 @@ Module.postRun.push(function(namespace/*the module object, the target for
|
||||
be able to work with multi-hundred-meg (or larger) blobs, and
|
||||
passing around arrays of those may quickly exhaust the JS
|
||||
engine's memory.
|
||||
|
||||
TODOs include, but are not limited to:
|
||||
|
||||
- The ability to manage multiple DB handles. This can
|
||||
potentially be done via a simple mapping of DB.filename or
|
||||
DB._pDb (`sqlite3*` handle) to DB objects. The open()
|
||||
interface would need to provide an ID (probably DB._pDb) back
|
||||
to the user which can optionally be passed as an argument to
|
||||
the other APIs (they'd default to the first-opened DB, for
|
||||
ease of use). Client-side usability of this feature would
|
||||
benefit from making another wrapper class (or a singleton)
|
||||
available to the main thread, with that object proxying all(?)
|
||||
communication with the worker.
|
||||
|
||||
- Revisit how virtual files are managed. We currently delete DBs
|
||||
from the virtual filesystem when we close them, for the sake
|
||||
of saving memory (the VFS lives in RAM). Supporting multiple
|
||||
DBs may require that we give up that habit. Similarly, fully
|
||||
supporting ATTACH, where a user can upload multiple DBs and
|
||||
ATTACH them, also requires the that we manage the VFS entries
|
||||
better. As of this writing, ATTACH will fail fatally in the
|
||||
fiddle app (but not the lower-level APIs) because it runs in
|
||||
safe mode, where ATTACH is disabled.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -126,6 +126,21 @@ INSERT INTO t(a,b) VALUES(1,2),(3,4),(?,?);`,
|
||||
assert(null === db.selectValue("select $a",{$a:null}));
|
||||
};
|
||||
|
||||
const testAttach = function(db){
|
||||
log("Testing ATTACH...");
|
||||
db.exec({
|
||||
sql:[
|
||||
"attach 'foo.db' as foo",
|
||||
"create table foo.bar(a)",
|
||||
"insert into foo.bar(a) values(1),(2),(3)"
|
||||
].join(';'),
|
||||
multi: true
|
||||
});
|
||||
T.assert(2===db.selectValue('select a from foo.bar where a>1 order by a'));
|
||||
db.exec("detach foo");
|
||||
T.mustThrow(()=>db.exec("select * from foo.bar"));
|
||||
};
|
||||
|
||||
const runTests = function(Module){
|
||||
T.assert(Module._free instanceof Function).
|
||||
assert(Module.allocate instanceof Function).
|
||||
@ -141,8 +156,12 @@ INSERT INTO t(a,b) VALUES(1,2),(3,4),(?,?);`,
|
||||
try {
|
||||
log("DB:",db.filename);
|
||||
[
|
||||
test1, testUDF
|
||||
].forEach((f)=>f(db, sqlite3));
|
||||
test1, testUDF, testAttach
|
||||
].forEach((f)=>{
|
||||
const t = T.counter;
|
||||
f(db, sqlite3);
|
||||
log("Test count:",T.counter - t);
|
||||
});
|
||||
}finally{
|
||||
db.close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user