aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-oo1.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-03 01:59:03 +0000
committerstephan <stephan@noemail.net>2022-12-03 01:59:03 +0000
commita37fed0f6289faa31dad019785092c6e2f92a08b (patch)
tree0d14a3def1b1e433d514d0f8682485aedeac00c9 /ext/wasm/api/sqlite3-api-oo1.js
parentbb4e4a4840530da37c6fdaabc9769a1996f25809 (diff)
downloadsqlite-a37fed0f6289faa31dad019785092c6e2f92a08b.tar.gz
sqlite-a37fed0f6289faa31dad019785092c6e2f92a08b.zip
Rework the oo1.DB's distinct-per-VFS post-open() step to accept either a batch of SQL or a callback function. Increase OPFS's busy timeout to 10s.
FossilOrigin-Name: 9feefe253ac487cb52be6bdf91bdd305963266716baa08f2bf9505954ee76321
Diffstat (limited to 'ext/wasm/api/sqlite3-api-oo1.js')
-rw-r--r--ext/wasm/api/sqlite3-api-oo1.js41
1 files changed, 28 insertions, 13 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js
index 45c2ba913..e077b0c50 100644
--- a/ext/wasm/api/sqlite3-api-oo1.js
+++ b/ext/wasm/api/sqlite3-api-oo1.js
@@ -78,8 +78,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}.bind({counter: 0}));
/**
- A map of sqlite3_vfs pointers to SQL code to run when the DB
- constructor opens a database with the given 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 __vfsPostOpenSql = Object.create(null);
@@ -160,15 +162,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
capi.sqlite3_trace_v2(pDb, capi.SQLITE_TRACE_STMT,
__dbTraceToConsole, 0);
}
- // Check for per-VFS post-open SQL...
- const pVfs = capi.sqlite3_js_db_vfs(pDb);
- //console.warn("Opened db",fn,"with vfs",vfsName,pVfs);
- if(!pVfs) toss3("Internal error: cannot get VFS for new db handle.");
- const postInitSql = __vfsPostOpenSql[pVfs];
- if(postInitSql){
- rc = capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0);
- checkSqlite3Rc(pDb, rc);
- }
}catch( e ){
if( pDb ) capi.sqlite3_close_v2(pDb);
throw e;
@@ -178,12 +171,34 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
this.filename = fnJs;
__ptrMap.set(this, pDb);
__stmtMap.set(this, Object.create(null));
+ try{
+ // Check for per-VFS post-open SQL/callback...
+ const pVfs = capi.sqlite3_js_db_vfs(pDb);
+ if(!pVfs) toss3("Internal error: cannot get VFS for new db handle.");
+ const postInitSql = __vfsPostOpenSql[pVfs];
+ if(postInitSql instanceof Function){
+ postInitSql(this, sqlite3);
+ }else if(postInitSql){
+ checkSqlite3Rc(
+ pDb, capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0)
+ );
+ }
+ }catch(e){
+ this.close();
+ throw e;
+ }
};
/**
Sets SQL which should be exec()'d on a DB instance after it is
- opened with the given VFS pointer. This is intended only for use
- by DB subclasses or sqlite3_vfs implementations.
+ opened with the given VFS pointer. The SQL may be any type
+ supported by the "flexible-string" 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 implementations.
*/
dbCtorHelper.setVfsPostOpenSql = function(pVfs, sql){
__vfsPostOpenSql[pVfs] = sql;