aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/api')
-rw-r--r--ext/wasm/api/sqlite3-api-oo1.c-pp.js50
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js13
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs.c-pp.js29
3 files changed, 33 insertions, 59 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.c-pp.js b/ext/wasm/api/sqlite3-api-oo1.c-pp.js
index c579b5ddf..55d7356e2 100644
--- a/ext/wasm/api/sqlite3-api-oo1.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-oo1.c-pp.js
@@ -79,14 +79,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}
}.bind({counter: 0}));
- /**
- A map of sqlite3_vfs pointers to SQL code or a callback function
- to run when the DB constructor opens a database with the given
- VFS. In the latter case, the call signature is (theDbObject,sqlite3Namespace)
- and the callback is expected to throw on error.
- */
- const __vfsPostOpenSql = Object.create(null);
-
//#if enable-see
/**
Converts ArrayBuffer or Uint8Array ba into a string of hex
@@ -279,7 +271,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
// Check for per-VFS post-open SQL/callback...
const pVfs = capi.sqlite3_js_db_vfs(pDb)
|| toss3("Internal error: cannot get VFS for new db handle.");
- const postInitSql = __vfsPostOpenSql[pVfs];
+ const postInitSql = __vfsPostOpenCallback[pVfs];
if(postInitSql){
/**
Reminder: if this db is encrypted and the client did _not_ pass
@@ -302,19 +294,39 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}
};
+
/**
- Sets SQL which should be exec()'d on a DB instance after it is
- opened with the given VFS pointer. The SQL may be any type
- supported by the "string:flexible" function argument conversion.
- Alternately, the 2nd argument may be a function, in which case it
- is called with (theOo1DbObject,sqlite3Namespace) at the end of
- the DB() constructor. The function must throw on error, in which
- case the db is closed and the exception is propagated. This
- function is intended only for use by DB subclasses or sqlite3_vfs
+ A map of sqlite3_vfs pointers to SQL code or a callback function
+ to run when the DB constructor opens a database with the given
+ VFS. In the latter case, the call signature is
+ (theDbObject,sqlite3Namespace) and the callback is expected to
+ throw on error.
+ */
+ const __vfsPostOpenCallback = Object.create(null);
+
+ /**
+ Sets a callback which should be called after a db is opened with
+ the given sqlite3_vfs pointer. The 2nd argument must be a
+ function, which gets called with
+ (theOo1DbObject,sqlite3Namespace) at the end of the DB()
+ constructor. The function must throw on error, in which case the
+ db is closed and the exception is propagated. This function is
+ intended only for use by DB subclasses or sqlite3_vfs
implementations.
+
+ Prior to 2024-07-22, it was legal to pass SQL code as the second
+ argument, but that can interfere with a client's ability to run
+ pragmas which must be run before anything else, namely (pragma
+ locking_mode=exclusive) for use with WAL mode. That capability
+ had only ever been used as an internal detail of the two OPFS
+ VFSes, and they no longer use it that way.
*/
- dbCtorHelper.setVfsPostOpenSql = function(pVfs, sql){
- __vfsPostOpenSql[pVfs] = sql;
+ dbCtorHelper.setVfsPostOpenCallback = function(pVfs, callback){
+ if( !(callback instanceof Function)){
+ toss3("dbCtorHelper.setVfsPostOpenCallback() should not be used with "+
+ "a non-function argument.",arguments);
+ }
+ __vfsPostOpenCallback[pVfs] = callback;
};
/**
diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
index 86ba3add8..d423bb0bb 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
@@ -78,8 +78,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
capi.SQLITE_OPEN_MAIN_DB |
capi.SQLITE_OPEN_MAIN_JOURNAL |
capi.SQLITE_OPEN_SUPER_JOURNAL |
- capi.SQLITE_OPEN_WAL /* noting that WAL support is
- unavailable in the WASM build.*/;
+ capi.SQLITE_OPEN_WAL;
/** Subdirectory of the VFS's space where "opaque" (randomly-named)
files are stored. Changing this effectively invalidates the data
@@ -1280,16 +1279,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
};
OpfsSAHPoolDb.prototype = Object.create(oo1.DB.prototype);
poolUtil.OpfsSAHPoolDb = OpfsSAHPoolDb;
- oo1.DB.dbCtorHelper.setVfsPostOpenSql(
- theVfs.pointer,
- function(oo1Db, sqlite3){
- sqlite3.capi.sqlite3_exec(oo1Db, [
- /* See notes in sqlite3-vfs-opfs.js */
- "pragma journal_mode=DELETE;",
- "pragma cache_size=-16384;"
- ], 0, 0, 0);
- }
- );
}/*extend sqlite3.oo1*/
thePool.log("VFS initialized.");
return poolUtil;
diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
index ef36b6062..2d11b3583 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
@@ -1288,40 +1288,13 @@ const installOpfsVfs = function callee(options){
OpfsDb.prototype = Object.create(sqlite3.oo1.DB.prototype);
sqlite3.oo1.OpfsDb = OpfsDb;
OpfsDb.importDb = opfsUtil.importDb;
- sqlite3.oo1.DB.dbCtorHelper.setVfsPostOpenSql(
+ sqlite3.oo1.DB.dbCtorHelper.setVfsPostOpenCallback(
opfsVfs.pointer,
function(oo1Db, sqlite3){
/* Set a relatively high default busy-timeout handler to
help OPFS dbs deal with multi-tab/multi-worker
contention. */
sqlite3.capi.sqlite3_busy_timeout(oo1Db, 10000);
- sqlite3.capi.sqlite3_exec(oo1Db, [
- /* As of July 2023, the PERSIST journal mode on OPFS is
- somewhat slower than DELETE or TRUNCATE (it was faster
- before Chrome version 108 or 109). TRUNCATE and DELETE
- have very similar performance on OPFS.
-
- Roy Hashimoto notes that TRUNCATE and PERSIST modes may
- decrease OPFS concurrency because multiple connections
- can open the journal file in those modes:
-
- https://github.com/rhashimoto/wa-sqlite/issues/68
-
- Given that, and the fact that testing has not revealed
- any appreciable difference between performance of
- TRUNCATE and DELETE modes on OPFS, we currently (as of
- 2023-07-13) default to DELETE mode.
- */
- "pragma journal_mode=DELETE;",
- /*
- This vfs benefits hugely from cache on moderate/large
- speedtest1 --size 50 and --size 100 workloads. We
- currently rely on setting a non-default cache size when
- building sqlite3.wasm. If that policy changes, the cache
- can be set here.
- */
- "pragma cache_size=-16384;"
- ], 0, 0, 0);
}
);
}/*extend sqlite3.oo1*/