]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
shell: in WASM mode, permit ATTACH because the filesystem is a virtual sandbox and...
authorstephan <stephan@noemail.net>
Mon, 6 Jun 2022 04:09:44 +0000 (04:09 +0000)
committerstephan <stephan@noemail.net>
Mon, 6 Jun 2022 04:09:44 +0000 (04:09 +0000)
FossilOrigin-Name: f28de5b726999b913b442fa51355d020ba1f1662d2f7978380623c16438eb238

ext/fiddle/sqlite3-api.js
ext/fiddle/testing1.js
manifest
manifest.uuid
src/shell.c.in

index 1be4d9c77580b7011888403301231b8b9c9ccc6e..5057eb53f817ae01682121463b1856dfa775d956 100644 (file)
@@ -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.
     */
 
     /**
index 46af2c926b01f14b4555ffaa4cdd51a395a548b3..d6bc26dfa160789cefa852118477b40c95ef3081 100644 (file)
@@ -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();
         }
index 64bc96e5a9125ca133c319c59378e4076b8076f6..612c2dbbc5469b4ca12d8c42a94e3002af9a888d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sto\stest\scase\sin\sfts3corrupt.test.\sNo\schanges\sto\ssource\scode.
-D 2022-06-03T14:08:40.859
+C shell:\sin\sWASM\smode,\spermit\sATTACH\sbecause\sthe\sfilesystem\sis\sa\svirtual\ssandbox\sand\sATTACH\scan\sbe\sused\sto\sprovide\smore\simport/export\soptions.\sMinor\sdoc\supdates\sin\ssqlite3-api.js.
+D 2022-06-06T04:09:44.420
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -65,11 +65,11 @@ F ext/fiddle/fiddle-worker.js 88bc2193a6cb6a3f04d8911bed50a4401fe6f277de7a71ba83
 F ext/fiddle/fiddle.html 724f1cd4126616bc87f5871f78d3f7aaaf41e45c9728724627baab87e6af35f0
 F ext/fiddle/fiddle.js 2ce9a93aad55cbf64a16b607149847a64cc4dc4e13df8b6d2a0e964b4269dc6c
 F ext/fiddle/index.md d9c1c308d8074341bc3b11d1d39073cd77754cb3ca9aeb949f23fdd8323d81cf
-F ext/fiddle/sqlite3-api.js b32d23349cf32c54265d132387b5711a29d61c1fcf6159fbef72d1f04dda5e3c
+F ext/fiddle/sqlite3-api.js ccf4bd0c1c5bbb3be3469573423d6c53991941bec497eac63e9f17ea13bf8952
 F ext/fiddle/sqlite3-worker.js a9c2b614beca187dbdd8c053ec2770cc61ec1ac9c0ec6398ceb49a79f705a421
 F ext/fiddle/testing.css 750572dded671d2cf142bbcb27af5542522ac08db128245d0b9fe410aa1d7f2a
 F ext/fiddle/testing1.html ea1f3be727f78e420007f823912c1a03b337ecbb8e79449abc2244ad4fe15d9a
-F ext/fiddle/testing1.js b5bf7e33b35f02f4208e4d68eaa41e5ed42eaefd57e0a1131e87cba96d4808dc
+F ext/fiddle/testing1.js 68715f4716a30aa4dab0ce954d465f662486c8bc96a19a4fc8edbea4ac211fd2
 F ext/fiddle/testing2.html 9063b2430ade2fe9da4e711addd1b51a2741cf0c7ebf6926472a5e5dd63c0bc4
 F ext/fiddle/testing2.js 7b45b4e7fddbd51dbaf89b6722c02758051b34bac5a98c11b569a7e7572f88ee
 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
@@ -571,7 +571,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c a4eb3c617027fd049b07432f3b942ea7151fa793a332a11a7d0f58c9539e104f
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 8b98d3e5511d2789880ea4a12a4637803f69db5df04c81e1e93a5aac75c89b2a
-F src/shell.c.in b76e681f9e441928d574f21f9473ef615158bbeab1ae49f05ecab9d81730a51d
+F src/shell.c.in 0d5b571b82d846ad916739eaf5e7873677a477eb5a99ebecac904db1426199de
 F src/sqlite.h.in 172528c287399a34f188154017b7268bf82c6d5b780902e361958d2318c4e37c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h a988810c9b21c0dc36dc7a62735012339dc76fc7ab448fb0792721d30eacb69d
@@ -1975,8 +1975,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P f1dfbc4f7452154ca5190ac22e17fdabebb92833967b11f7dae21b8d3a5857bd
-R 0e53c4e5af03302c956c74fa1c3798cf
-U dan
-Z 035c36790d92294bdb53bee5aed3ce5b
+P d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25
+R dd896338802aeee36c510f5914b04fd2
+U stephan
+Z c59f8d92cfc32216e397bef16af41dcd
 # Remove this line to create a well-formed Fossil manifest.
index 23b700566792af382b024fe31c45ce3457984e1e..16b8fa7a96a234ef3af640c344290dfa831e81f2 100644 (file)
@@ -1 +1 @@
-d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25
\ No newline at end of file
+f28de5b726999b913b442fa51355d020ba1f1662d2f7978380623c16438eb238
\ No newline at end of file
index b03c96183dc4ca3df03b48b71cee5d18d613b4b9..c789212a496440ec8d2694b29506e536f0e36c08 100644 (file)
@@ -1838,7 +1838,11 @@ static int safeModeAuth(
   UNUSED_PARAMETER(zA4);
   switch( op ){
     case SQLITE_ATTACH: {
+#ifndef SQLITE_SHELL_WASM_MODE
+      /* In WASM builds the filesystem is a virtual sandbox, so
+      ** there's no harm in using ATTACH. */
       failIfSafeMode(p, "cannot run ATTACH in safe mode");
+#endif
       break;
     }
     case SQLITE_FUNCTION: {