diff options
author | stephan <stephan@noemail.net> | 2022-09-26 13:55:10 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-26 13:55:10 +0000 |
commit | 278d3faf1ffa6bbd14253865edba3e81631d0cb5 (patch) | |
tree | fe54c334cfee9001d5f3d1d7a05cb2d0d31f8735 /ext/wasm/api | |
parent | 1f095d482d1803deb9fcb60449e9ca1223018d73 (diff) | |
download | sqlite-278d3faf1ffa6bbd14253865edba3e81631d0cb5.tar.gz sqlite-278d3faf1ffa6bbd14253865edba3e81631d0cb5.zip |
Fiddle: replace db export routine with a C-side one which works for both Emscripten FS-hosted and OPFS-hosted db files. Minor code-adjacent cleanups.
FossilOrigin-Name: 3579a8d6f1f6cd3cd8aad9949536870c5fe7bae8c1778f700dd85d763e266b94
Diffstat (limited to 'ext/wasm/api')
-rw-r--r-- | ext/wasm/api/sqlite3-api-oo1.js | 45 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-api-opfs.js | 14 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 25 |
3 files changed, 21 insertions, 63 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index 25ca34dda..e0f812baa 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -1025,51 +1025,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ this.exec("ROLLBACK to SAVEPOINT oo1; RELEASE SAVEPOINT oo1"); throw e; } - }, - - /** - This function currently does nothing and always throws. It - WILL BE REMOVED pending other refactoring, to eliminate a hard - dependency on Emscripten. This feature will be moved into a - higher-level API or a runtime-configurable feature. - - That said, what its replacement should eventually do is... - - Exports a copy of this db's file as a Uint8Array and - returns it. It is technically not legal to call this while - any prepared statement are currently active because, - depending on the platform, it might not be legal to read - the db while a statement is locking it. Throws if this db - is not open or has any opened statements. - - The resulting buffer can be passed to this class's - constructor to restore the DB. - - Maintenance reminder: the corresponding sql.js impl of this - feature closes the current db, finalizing any active - statements and (seemingly unnecessarily) destroys any UDFs, - copies the file, and then re-opens it (without restoring - the UDFs). Those gymnastics are not necessary on the tested - platform but might be necessary on others. Because of that - eventuality, this interface currently enforces that no - statements are active when this is run. It will throw if - any are. - */ - exportBinaryImage: function(){ - toss3("exportBinaryImage() is slated for removal for portability reasons."); - /*********************** - The following is currently kept only for reference when - porting to some other layer, noting that we may well not be - able to implement this, at this level, when using the OPFS - VFS because of its exclusive locking policy. - - affirmDbOpen(this); - if(this.openStatementCount()>0){ - toss3("Cannot export with prepared statements active!", - "finalize() all statements and try again."); - } - return MODCFG.FS.readFile(this.filename, {encoding:"binary"}); - ***********************/ } }/*DB.prototype*/; diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index 2c22c03f7..e28e47ab6 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -637,7 +637,7 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) const rc = opRun('xFileSize', pFile); if(0==rc){ const sz = state.s11n.deserialize()[0]; - wasm.setMemValue(pSz64, BigInt(sz), 'i64'); + wasm.setMemValue(pSz64, sz, 'i64'); } mTimeEnd(); return rc; @@ -820,10 +820,12 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) } /* Install the vfs/io_methods into their C-level shared instances... */ - let inst = installMethod(opfsIoMethods); - for(let k of Object.keys(ioSyncWrappers)) inst(k, ioSyncWrappers[k]); - inst = installMethod(opfsVfs); - for(let k of Object.keys(vfsSyncWrappers)) inst(k, vfsSyncWrappers[k]); + for(let k of Object.keys(ioSyncWrappers)){ + installMethod(opfsIoMethods, k, ioSyncWrappers[k]); + } + for(let k of Object.keys(vfsSyncWrappers)){ + installMethod(opfsVfs, k, vfsSyncWrappers[k]); + } /** Syncronously deletes the given OPFS filesystem entry, ignoring @@ -831,7 +833,7 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) directory", the given name must be an absolute path. If the 2nd argument is truthy, deletion is recursive (use with caution!). - Returns true if the deletion succeeded and fails if it fails, + Returns true if the deletion succeeded and false if it fails, but cannot report the nature of the failure. */ opfsUtil.deleteEntry = function(fsEntryName,recursive=false){ diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 6a3bbc585..b5cd292fc 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -784,13 +784,16 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( } /** - Given an `sqlite3*` and an sqlite3_vfs name, returns a truthy - value (see below) if that db handle uses that VFS, else returns - false. If pDb is falsy then this function returns a truthy value - if the default VFS is that VFS. Results are undefined if pDb is - truthy but refers to an invalid pointer. - - The 2nd argument may either be a JS string or a C-string + Given an `sqlite3*`, an sqlite3_vfs name, and an optional db + name, returns a truthy value (see below) if that db handle uses + that VFS, else returns false. If pDb is falsy then the 3rd + argument is ignored and this function returns a truthy value if + the default VFS name matches that of the 2nd argument. Results + are undefined if pDb is truthy but refers to an invalid + pointer. The 3rd argument specifies the database name of the + given database connection to check, defaulting to the main db. + + The 2nd and 3rd arguments may either be a JS string or a C-string allocated from the wasm environment. The truthy value it returns is a pointer to the `sqlite3_vfs` @@ -801,11 +804,9 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( bad arguments cause a conversion error when passing into wasm-space, false is returned. */ - capi.sqlite3_web_db_uses_vfs = function(pDb,vfsName){ + capi.sqlite3_web_db_uses_vfs = function(pDb,vfsName,dbName="main"){ try{ - const pK = ('number'===vfsName) - ? capi.wasm.exports.sqlite3_vfs_find(vfsName) - : capi.sqlite3_vfs_find(vfsName); + const pK = capi.sqlite3_vfs_find(vfsName); if(!pK) return false; else if(!pDb){ return capi.sqlite3_vfs_find(0)===pK ? pK : false; @@ -814,7 +815,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( try{ return ( (0===capi.sqlite3_file_control( - pDb, "main", capi.SQLITE_FCNTL_VFS_POINTER, ppVfs + pDb, dbName, capi.SQLITE_FCNTL_VFS_POINTER, ppVfs )) && (capi.wasm.getPtrValue(ppVfs) === pK) ) ? pK : false; }finally{ |