aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/api')
-rw-r--r--ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras31
-rw-r--r--ext/wasm/api/sqlite3-api-glue.c-pp.js9
-rw-r--r--ext/wasm/api/sqlite3-api-oo1.c-pp.js71
-rw-r--r--ext/wasm/api/sqlite3-wasm.c7
4 files changed, 78 insertions, 40 deletions
diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras
index e635d93b3..01dad072e 100644
--- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras
+++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras
@@ -1,12 +1,27 @@
+_sqlite3_column_database_name
+_sqlite3_column_origin_name
+_sqlite3_column_table_name
+_sqlite3_create_module
+_sqlite3_create_module_v2
_sqlite3_create_window_function
-_sqlite3_progress_handler
-_sqlite3_set_authorizer
+_sqlite3_declare_vtab
+_sqlite3_drop_modules
_sqlite3_preupdate_blobwrite
_sqlite3_preupdate_count
_sqlite3_preupdate_depth
_sqlite3_preupdate_hook
_sqlite3_preupdate_new
_sqlite3_preupdate_old
+_sqlite3_progress_handler
+_sqlite3_set_authorizer
+_sqlite3_vtab_collation
+_sqlite3_vtab_distinct
+_sqlite3_vtab_in
+_sqlite3_vtab_in_first
+_sqlite3_vtab_in_next
+_sqlite3_vtab_nochange
+_sqlite3_vtab_on_conflict
+_sqlite3_vtab_rhs_value
_sqlite3changegroup_add
_sqlite3changegroup_add_strm
_sqlite3changegroup_delete
@@ -49,15 +64,3 @@ _sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter
-_sqlite3_create_module
-_sqlite3_create_module_v2
-_sqlite3_declare_vtab
-_sqlite3_drop_modules
-_sqlite3_vtab_collation
-_sqlite3_vtab_distinct
-_sqlite3_vtab_in
-_sqlite3_vtab_in_first
-_sqlite3_vtab_in_next
-_sqlite3_vtab_nochange
-_sqlite3_vtab_on_conflict
-_sqlite3_vtab_rhs_value
diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js
index a38b9cb5e..8d2d4a589 100644
--- a/ext/wasm/api/sqlite3-api-glue.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js
@@ -20,7 +20,6 @@
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
'use strict';
const toss = (...args)=>{throw new Error(args.join(' '))};
- const toss3 = sqlite3.SQLite3Error.toss;
const capi = sqlite3.capi, wasm = sqlite3.wasm, util = sqlite3.util;
globalThis.WhWasmUtilInstaller(wasm);
delete globalThis.WhWasmUtilInstaller;
@@ -368,6 +367,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
);
}/* sqlite3_set_authorizer() */
+ if( !!wasm.exports.sqlite3_column_origin_name ){
+ wasm.bindingSignatures.push(
+ ["sqlite3_column_database_name","string", "sqlite3_stmt*", "int"],
+ ["sqlite3_column_origin_name","string", "sqlite3_stmt*", "int"],
+ ["sqlite3_column_table_name","string", "sqlite3_stmt*", "int"]
+ );
+ }
+
if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
/* ^^^ "the problem" is that this is an optional feature and the
build-time function-export list does not currently take
diff --git a/ext/wasm/api/sqlite3-api-oo1.c-pp.js b/ext/wasm/api/sqlite3-api-oo1.c-pp.js
index 3d6a24c77..06f916002 100644
--- a/ext/wasm/api/sqlite3-api-oo1.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-oo1.c-pp.js
@@ -16,7 +16,6 @@
and it installs its deliverable as globalThis.sqlite3.oo1.
*/
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- const toss = (...args)=>{throw new Error(args.join(' '))};
const toss3 = (...args)=>{throw new sqlite3.SQLite3Error(...args)};
const capi = sqlite3.capi, wasm = sqlite3.wasm, util = sqlite3.util;
@@ -1061,18 +1060,18 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
const cbArgCache = Object.create(null)
/* 2nd arg for arg.cbArg, used by (at least) row-to-object
converter */;
- for(; stmt.step(); stmt._lockedByExec = false){
+ for( ; stmt.step(); __execLock.delete(stmt) ){
if(0===gotColNames++){
stmt.getColumnNames(cbArgCache.columnNames = (opt.columnNames || []));
}
- stmt._lockedByExec = true;
+ __execLock.add(stmt);
const row = arg.cbArg(stmt,cbArgCache);
if(resultRows) resultRows.push(row);
if(callback && false === callback.call(opt, row, stmt)){
break;
}
}
- stmt._lockedByExec = false;
+ __execLock.delete(stmt);
}
if(0===gotColNames){
/* opt.columnNames was provided but we visited no result rows */
@@ -1094,7 +1093,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}*/finally{
wasm.scopedAllocPop(stack);
if(stmt){
- delete stmt._lockedByExec;
+ __execLock.delete(stmt);
stmt.finalize();
}
}
@@ -1388,7 +1387,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
/**
Starts a transaction, calls the given callback, and then either
- rolls back or commits the savepoint, depending on whether the
+ rolls back or commits the transaction, depending on whether the
callback throws. The callback is passed this db object as its
only argument. On success, returns the result of the
callback. Throws on error.
@@ -1511,7 +1510,30 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
};
/**
- If stmt._lockedByExec is truthy, this throws an exception
+ Each Stmt object which is "locked" by DB.exec() gets an entry
+ here to note that "lock".
+
+ The reason this is in place is because exec({callback:...})'s
+ callback gets access to the Stmt objects created internally by
+ exec() but it must not use certain Stmt APIs.
+ */
+ const __execLock = new Set();
+ /**
+ This is a Stmt.get() counterpart of __execLock. Each time
+ Stmt.step() returns true, the statement is added to this set,
+ indicating that Stmt.get() is legal. Stmt APIs which invalidate
+ that status remove the Stmt object from this set, which will
+ cause Stmt.get() to throw with a descriptive error message
+ instead of a more generic "API misuse" if we were to allow that
+ call to reach the C API.
+ */
+ const __stmtMayGet = new Set();
+
+ /**
+ Stmt APIs which are prohibited on locked objects must call
+ affirmNotLockedByExec() before doing any work.
+
+ If __execLock.has(stmt) is truthy, this throws an exception
complaining that the 2nd argument (an operation name,
e.g. "bind()") is not legal while the statement is "locked".
Locking happens before an exec()-like callback is passed a
@@ -1519,7 +1541,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
finalize the statement. If it does not throw, it returns stmt.
*/
const affirmNotLockedByExec = function(stmt,currentOpName){
- if(stmt._lockedByExec){
+ if(__execLock.has(stmt)){
toss3("Operation is illegal when statement is locked:",currentOpName);
}
return stmt;
@@ -1604,7 +1626,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
toss3("Unsupported bind() argument type: "+(typeof val));
}
if(rc) DB.checkRc(stmt.db.pointer, rc);
- stmt._mayGet = false;
return stmt;
};
@@ -1627,9 +1648,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
const rc = capi.sqlite3_finalize(this.pointer);
delete __stmtMap.get(this.db)[this.pointer];
__ptrMap.delete(this);
- delete this._mayGet;
+ __execLock.delete(this);
+ __stmtMayGet.delete(this);
delete this.parameterCount;
- delete this._lockedByExec;
delete this.db;
return rc;
}
@@ -1643,7 +1664,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
clearBindings: function(){
affirmNotLockedByExec(affirmStmtOpen(this), 'clearBindings()')
capi.sqlite3_clear_bindings(this.pointer);
- this._mayGet = false;
+ __stmtMayGet.delete(this);
return this;
},
/**
@@ -1669,7 +1690,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
affirmNotLockedByExec(this,'reset()');
if(alsoClearBinds) this.clearBindings();
const rc = capi.sqlite3_reset(affirmStmtOpen(this).pointer);
- this._mayGet = false;
+ __stmtMayGet.delete(this);
checkSqlite3Rc(this.db, rc);
return this;
},
@@ -1756,7 +1777,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}else if(!this.parameterCount){
toss3("This statement has no bindable parameters.");
}
- this._mayGet = false;
+ __stmtMayGet.delete(this);
if(null===arg){
/* bind NULL */
return bindOne(this, ndx, BindTypes.null, arg);
@@ -1821,14 +1842,18 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
affirmNotLockedByExec(this, 'step()');
const rc = capi.sqlite3_step(affirmStmtOpen(this).pointer);
switch(rc){
- case capi.SQLITE_DONE: return this._mayGet = false;
- case capi.SQLITE_ROW: return this._mayGet = true;
- default:
- this._mayGet = false;
- sqlite3.config.warn("sqlite3_step() rc=",rc,
- capi.sqlite3_js_rc_str(rc),
- "SQL =", capi.sqlite3_sql(this.pointer));
- DB.checkRc(this.db.pointer, rc);
+ case capi.SQLITE_DONE:
+ __stmtMayGet.delete(this);
+ return false;
+ case capi.SQLITE_ROW:
+ __stmtMayGet.add(this);
+ return true;
+ default:
+ __stmtMayGet.delete(this);
+ sqlite3.config.warn("sqlite3_step() rc=",rc,
+ capi.sqlite3_js_rc_str(rc),
+ "SQL =", capi.sqlite3_sql(this.pointer));
+ DB.checkRc(this.db.pointer, rc);
}
},
/**
@@ -1913,7 +1938,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
getJSON() can be used for that.
*/
get: function(ndx,asType){
- if(!affirmStmtOpen(this)._mayGet){
+ if(!__stmtMayGet.has(affirmStmtOpen(this))){
toss3("Stmt.step() has not (recently) returned true.");
}
if(Array.isArray(ndx)){
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c
index d9f0f08eb..ee8a10209 100644
--- a/ext/wasm/api/sqlite3-wasm.c
+++ b/ext/wasm/api/sqlite3-wasm.c
@@ -135,9 +135,12 @@
/*
** If SQLITE_WASM_BARE_BONES is defined, undefine most of the ENABLE
-** macros.
+** macros. This will, when using the canonical makefile, also elide
+** any C functions from the WASM exports which are listed in
+** ./EXPORT_FUNCTIONS.sqlite3-extras.
*/
#ifdef SQLITE_WASM_BARE_BONES
+# undef SQLITE_ENABLE_COLUMN_METADATA
# undef SQLITE_ENABLE_DBPAGE_VTAB
# undef SQLITE_ENABLE_DBSTAT_VTAB
# undef SQLITE_ENABLE_EXPLAIN_COMMENTS
@@ -1157,7 +1160,7 @@ const char * sqlite3__wasm_enum_json(void){
{ /* Validate that the above struct sizeof()s match
** expectations. We could improve upon this by
** checking the offsetof() for each member. */
- const sqlite3_index_info siiCheck;
+ const sqlite3_index_info siiCheck = {0};
#define IndexSzCheck(T,M) \
(sizeof(T) == sizeof(*siiCheck.M))
if(!IndexSzCheck(sqlite3_index_constraint,aConstraint)