diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index e0f812baa7..4f7ffe1cd8 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -495,24 +495,25 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } }, /** - Similar to this.filename but will return a falsy value for - special names like ":memory:". Throws if the DB has been - closed. If passed an argument it then it will return the + Similar to the this.filename property but will return a falsy + value for special names like ":memory:". Throws if the DB has + been closed. If passed an argument it then it will return the filename of the ATTACHEd db with that name, else it assumes a - name of `main`. + name of `main`. The argument may be either a JS string or + a pointer to a WASM-allocated C-string. */ getFilename: function(dbName='main'){ return capi.sqlite3_db_filename(affirmDbOpen(this).pointer, dbName); }, /** Returns true if this db instance has a name which resolves to a - file. If the name is "" or ":memory:", it resolves to false. + file. If the name is "" or starts with ":", it resolves to false. Note that it is not aware of the peculiarities of URI-style names and a URI-style name for a ":memory:" db will fool it. Returns false if this db is closed. */ hasFilename: function(){ - return this.filename && ':memory'!==this.filename; + return this.filename && ':'!==this.filename[0]; }, /** Returns the name of the given 0-based db number, as documented @@ -525,9 +526,13 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ Compiles the given SQL and returns a prepared Stmt. This is the only way to create new Stmt objects. Throws on error. - The given SQL must be a string, a Uint8Array holding SQL, or a - WASM pointer to memory holding the NUL-terminated SQL string. - If the SQL contains no statements, an SQLite3Error is thrown. + The given SQL must be a string, a Uint8Array holding SQL, a + WASM pointer to memory holding the NUL-terminated SQL string, + or an array of strings. In the latter case, the array is + concatenated together, with no separators, to form the SQL + string (arrays are often a convenient way to formulate long + statements). If the SQL contains no statements, an + SQLite3Error is thrown. Design note: the C API permits empty SQL, reporting it as a 0 result code and a NULL stmt pointer. Supporting that case here @@ -541,6 +546,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ prepare: function(sql){ affirmDbOpen(this); + if(Array.isArray(sql)) sql = sql.join(''); const stack = capi.wasm.scopedAllocPush(); let ppStmt, pStmt; try{ diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index e28e47ab6c..a346443f56 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -883,12 +883,15 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) hook in to any C-side calls to sqlite3_initialize(), so we cannot add an after-initialize callback mechanism. */ - opfsUtil.reregisterVfs = (asDefault=false)=>{ + opfsUtil.registerVfs = (asDefault=false)=>{ return capi.wasm.exports.sqlite3_vfs_register( opfsVfs.pointer, asDefault ? 1 : 0 ); }; - + + //TODO to support fiddle db upload: + //opfsUtil.createFile = function(absName, content=undefined){...} + if(sqlite3.oo1){ opfsUtil.OpfsDb = function(...args){ const opt = sqlite3.oo1.dbCtorHelper.normalizeArgs(...args); diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index b5cd292fc5..b2d8809377 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -120,7 +120,7 @@ the `free(3)`-compatible routine for the WASM environment. Defaults to `"free"`. - - `persistentDirName`[^1]: if the environment supports persistent storage, this + - `wasmfsOpfsDir`[^1]: if the environment supports persistent storage, this directory names the "mount point" for that directory. It must be prefixed by `/` and may currently contain only a single directory-name part. Using the root directory name is not supported by any current persistent backend. @@ -157,7 +157,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( })(), allocExportName: 'malloc', deallocExportName: 'free', - persistentDirName: '/persistent' + wasmfsOpfsDir: '/opfs' }; Object.keys(configDefaults).forEach(function(k){ config[k] = Object.getOwnPropertyDescriptor(apiConfig, k) @@ -174,7 +174,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( [ // If any of these config options are functions, replace them with // the result of calling that function... - 'Module', 'exports', 'memory', 'persistentDirName' + 'Module', 'exports', 'memory', 'wasmfsOpfsDir' ].forEach((k)=>{ if('function' === typeof config[k]){ config[k] = config[k](); @@ -185,8 +185,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( all args with a space between each. */ const toss = (...args)=>{throw new Error(args.join(' '))}; - if(config.persistentDirName && !/^\/[^/]+$/.test(config.persistentDirName)){ - toss("config.persistentDirName must be falsy or in the form '/dir-name'."); + if(config.wasmfsOpfsDir && !/^\/[^/]+$/.test(config.wasmfsOpfsDir)){ + toss("config.wasmfsOpfsDir must be falsy or in the form '/dir-name'."); } /** @@ -727,7 +727,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( capi.sqlite3_web_persistent_dir = function(){ if(undefined !== __persistentDir) return __persistentDir; // If we have no OPFS, there is no persistent dir - const pdir = config.persistentDirName; + const pdir = config.wasmfsOpfsDir; if(!pdir || !self.FileSystemHandle || !self.FileSystemDirectoryHandle @@ -748,7 +748,6 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( const pVfs = sqlite3.capi.sqlite3_vfs_find("unix-none"); if(pVfs){ capi.sqlite3_vfs_register(pVfs,1); - console.warn("Installed 'unix-none' as the default sqlite3 VFS."); } return __persistentDir = pdir; }else{ diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index cf9a1a3db6..8750d9b207 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -571,7 +571,7 @@ int sqlite3_wasm_vfs_unlink(const char * zName){ WASM_KEEP int sqlite3_wasm_init_wasmfs(const char *zMountPoint){ static backend_t pOpfs = 0; - if( !zMountPoint || !*zMountPoint ) zMountPoint = "/persistent"; + if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs"; if( !pOpfs ){ pOpfs = wasmfs_create_opfs_backend(); if( pOpfs ){ @@ -595,7 +595,8 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){ } #else WASM_KEEP -int sqlite3_wasm_init_wasmfs(void){ +int sqlite3_wasm_init_wasmfs(const char *zUnused){ + if(zUnused){/*unused*/} return SQLITE_NOTFOUND; } #endif /* __EMSCRIPTEN__ && SQLITE_WASM_WASMFS */ diff --git a/ext/wasm/common/SqliteTestUtil.js b/ext/wasm/common/SqliteTestUtil.js index 779f271fb4..277ab55294 100644 --- a/ext/wasm/common/SqliteTestUtil.js +++ b/ext/wasm/common/SqliteTestUtil.js @@ -221,7 +221,7 @@ sqlite3 API. */ sqlite3ApiConfig: { - persistentDirName: "/persistent" + wasmfsOpfsDir: "/opfs" }, /** Intended to be called by apps which need to call the diff --git a/ext/wasm/demo-123.js b/ext/wasm/demo-123.js index c7dc4c769c..5ba1f1df77 100644 --- a/ext/wasm/demo-123.js +++ b/ext/wasm/demo-123.js @@ -44,7 +44,7 @@ oo = sqlite3.oo1/*high-level OO API*/; log("sqlite3 version",capi.sqlite3_libversion(), capi.sqlite3_sourceid()); const db = new oo.DB("/mydb.sqlite3"); - log("transient b =",db.filename); + log("transient db =",db.filename); /** Never(!) rely on garbage collection to clean up DBs and (especially) prepared statements. Always wrap their lifetimes @@ -82,7 +82,12 @@ } log("Insert using a prepared statement..."); - let q = db.prepare("insert into t(a,b) values(?,?)"); + let q = db.prepare([ + // SQL may be a string or array of strings + // (concatenated w/o separators). + "insert into t(a,b) ", + "values(?,?)" + ]); try { for( i = 100; i < 103; ++i ){ q.bind( [i, i*2] ).step(); diff --git a/ext/wasm/fiddle/fiddle-worker.js b/ext/wasm/fiddle/fiddle-worker.js index dd82914655..b0c0526f8c 100644 --- a/ext/wasm/fiddle/fiddle-worker.js +++ b/ext/wasm/fiddle/fiddle-worker.js @@ -170,7 +170,7 @@ stdout("\nOPFS is available. To open a persistent db, use:\n\n", " .open file:name?vfs=opfs\n\nbut note that some", "features (e.g. upload) do not yet work with OPFS."); - S.opfs.reregisterVfs(); + S.opfs.registerVfs(); } stdout('\nEnter ".help" for usage hints.'); this.exec([ // initialization commands... diff --git a/ext/wasm/index.html b/ext/wasm/index.html index ee31306bb7..20668db20e 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -14,7 +14,7 @@ builds. All of them require that this directory have been "make"d first. The intent is that this page be run using: -
+althttpd -page index.html
althttpd -enable-sab -page index.html
-enable-sab
flag for that.