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-glue.js4
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js17
-rw-r--r--ext/wasm/api/sqlite3-api-worker1.js8
-rw-r--r--ext/wasm/api/sqlite3-wasm.c36
4 files changed, 35 insertions, 30 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js
index bfacef3b3..5768e44cb 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -72,10 +72,12 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
('sqlite3_stmt*', aPtr)
('sqlite3_context*', aPtr)
('sqlite3_value*', aPtr)
+ ('sqlite3_vfs*', aPtr)
('void*', aPtr);
wasm.xWrap.resultAdapter('sqlite3*', aPtr)
- ('sqlite3_stmt*', aPtr)
('sqlite3_context*', aPtr)
+ ('sqlite3_stmt*', aPtr)
+ ('sqlite3_vfs*', aPtr)
('void*', aPtr);
/**
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index f59d86506..d02d6b054 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -861,13 +861,12 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
/**
Functions which are intended solely for API-internal use by the
WASM components, not client code. These get installed into
- wasm.
-
- TODO: get rid of sqlite3_wasm_vfs_unlink(). It is ill-conceived
- and only rarely actually useful.
+ capi.wasm.
*/
wasm.bindingSignatures.wasm = [
- ["sqlite3_wasm_vfs_unlink", "int", "string"]
+ ["sqlite3_wasm_db_reset", "int", "sqlite3*"],
+ ["sqlite3_wasm_db_vfs", "sqlite3_vfs*", "sqlite3*","string"],
+ ["sqlite3_wasm_vfs_unlink", "int", "sqlite3_vfs*","string"]
];
@@ -919,7 +918,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
This method always adjusts the given value to be a multiple
of 8 bytes because failing to do so can lead to incorrect
results when reading and writing 64-bit values from/to the WASM
- heap.
+ heap. Similarly, the returned address is always 8-byte aligned.
*/
alloc: (n)=>{
return wasm.exports.sqlite3_wasm_pstack_alloc(n)
@@ -1074,12 +1073,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
Returns true if sqlite3.capi.sqlite3_wasmfs_opfs_dir() is a
non-empty string and the given name starts with (that string +
'/'), else returns false.
-
- Potential (but arguable) TODO: return true if the name is one of
- (":localStorage:", "local", ":sessionStorage:", "session") and
- kvvfs is available.
*/
- capi.sqlite3_web_filename_is_persistent = function(name){
+ capi.sqlite3_wasmfs_filename_is_persistent = function(name){
const p = capi.sqlite3_wasmfs_opfs_dir();
return (p && name) ? name.startsWith(p+'/') : false;
};
diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js
index 55faab282..6c0900a50 100644
--- a/ext/wasm/api/sqlite3-api-worker1.js
+++ b/ext/wasm/api/sqlite3-api-worker1.js
@@ -365,13 +365,11 @@ sqlite3.initWorker1API = function(){
if(db){
delete this.dbs[getDbId(db)];
const filename = db.getFilename();
+ const pVfs = sqlite3.capi.wasm.sqlite3_wasm_db_vfs(db.pointer, 0);
db.close();
if(db===this.defaultDb) this.defaultDb = undefined;
- if(alsoUnlink && filename){
- /* This isn't necessarily correct: the db might be using a
- VFS other than the default. How do we best resolve this
- without having to special-case the opfs VFSes? */
- sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(filename);
+ if(alsoUnlink && filename && pVfs){
+ sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(pVfs, filename);
}
}
},
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c
index cda4e7ae2..1decf0593 100644
--- a/ext/wasm/api/sqlite3-wasm.c
+++ b/ext/wasm/api/sqlite3-wasm.c
@@ -809,22 +809,16 @@ const char * sqlite3_wasm_enum_json(void){
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
-** Do not use this function, even for internal use: it was
-** ill-conceived and will be removed once the JS code which still
-** calls it has been weeded out.
-**
-** This function invokes the xDelete method of the default VFS,
-** passing on the given filename. If zName is NULL, no default VFS is
-** found, or it has no xDelete method, SQLITE_MISUSE is returned, else
-** the result of the xDelete() call is returned.
+** This function invokes the xDelete method of the given VFS (or the
+** default VFS if pVfs is NULL), passing on the given filename. If
+** zName is NULL, no default VFS is found, or it has no xDelete
+** method, SQLITE_MISUSE is returned, else the result of the xDelete()
+** call is returned.
*/
SQLITE_WASM_KEEP
-int sqlite3_wasm_vfs_unlink(const char * zName){
+int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char * zName){
int rc = SQLITE_MISUSE /* ??? */;
- sqlite3_vfs * const pVfs = sqlite3_vfs_find(0);
-#if defined(__EMSCRIPTEN__)
- emscripten_console_warn("sqlite3_wasm_vfs_unlink() will be removed.");
-#endif
+ if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
if( zName && pVfs && pVfs->xDelete ){
rc = pVfs->xDelete(pVfs, zName, 1);
}
@@ -835,6 +829,22 @@ int sqlite3_wasm_vfs_unlink(const char * zName){
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
**
+** Returns a pointer to the given DB's VFS for the given DB name,
+** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
+** given name is open.
+*/
+SQLITE_WASM_KEEP
+sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
+ sqlite3_vfs * pVfs = 0;
+ sqlite3_file_control(pDb, zDbName ? zDbName : "main",
+ SQLITE_FCNTL_VFS_POINTER, &pVfs);
+ return pVfs;
+}
+
+/*
+** This function is NOT part of the sqlite3 public API. It is strictly
+** for use by the sqlite project's own JS/WASM bindings.
+**
** This function resets the given db pointer's database as described at
**
** https://www.sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigresetdatabase