aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-25 17:09:34 +0000
committerstephan <stephan@noemail.net>2022-12-25 17:09:34 +0000
commit73bf9d5fed1ed13e4bfdd4c338115e3dd4e95c6b (patch)
tree69a45b7e9c044e1cf06052fac4843995c7634f31 /ext/wasm/api
parent7015aa9f4957c3131c8bc814c81c4c5d2dea8f89 (diff)
downloadsqlite-73bf9d5fed1ed13e4bfdd4c338115e3dd4e95c6b.tar.gz
sqlite-73bf9d5fed1ed13e4bfdd4c338115e3dd4e95c6b.zip
Replace the "manual" implementation of sqlite3.capi.sqlite3_exec() with a briefer "automated" one via the [7f9ace1b11a67] feature addition. Minor code-adjacent internal cleanups.
FossilOrigin-Name: 4888957baf18c6763f959fbba998a74156ff656368779107f502b926e9e9d949
Diffstat (limited to 'ext/wasm/api')
-rw-r--r--ext/wasm/api/sqlite3-api-glue.js72
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js2
2 files changed, 27 insertions, 47 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js
index 85c549ae3..dcdc17942 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -127,9 +127,32 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
["sqlite3_errmsg", "string", "sqlite3*"],
["sqlite3_error_offset", "int", "sqlite3*"],
["sqlite3_errstr", "string", "int"],
- /*["sqlite3_exec", "int", "sqlite3*", "string", "*", "*", "**"
- Handled seperately to perform translation of the callback
- into a WASM-usable one. ],*/
+ ["sqlite3_exec", "int", [
+ "sqlite3*", "string:flexible",
+ new wasm.xWrap.FuncPtrAdapter({
+ signature: 'i(pipp)',
+ bindScope: 'transient',
+ callProxy: (callback)=>{
+ let aNames;
+ return (pVoid, nCols, pColVals, pColNames)=>{
+ try {
+ const aVals = wasm.cArgvToJs(nCols, pColVals);
+ if(!aNames) aNames = wasm.cArgvToJs(nCols, pColNames);
+ return callback(aVals, aNames) | 0;
+ }catch(e){
+ /* If we set the db error state here, the higher-level
+ exec() call replaces it with its own, so we have no way
+ of reporting the exception message except the console. We
+ must not propagate exceptions through the C API. Though
+ we make an effort to report OOM here, sqlite3_exec()
+ translates that into SQLITE_ABORT as well. */
+ return e.resultCode || capi.SQLITE_ERROR;
+ }
+ }
+ }
+ }),
+ "*", "**"
+ ]],
["sqlite3_expanded_sql", "string", "sqlite3_stmt*"],
["sqlite3_extended_errcode", "int", "sqlite3*"],
["sqlite3_extended_result_codes", "int", "sqlite3*", "int"],
@@ -591,49 +614,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}/*sqlite3_create_collation() and friends*/
- {/* Special-case handling of sqlite3_exec() */
- const __exec = wasm.xWrap("sqlite3_exec", "int",
- ["sqlite3*", "string:flexible",
- new wasm.xWrap.FuncPtrAdapter({
- signature: 'i(pipp)',
- bindScope: 'transient'
- }), "*", "**"]);
- /* Documented in the api object's initializer. */
- capi.sqlite3_exec = function f(pDb, sql, callback, pVoid, pErrMsg){
- if(f.length!==arguments.length){
- return __dbArgcMismatch(pDb,"sqlite3_exec",f.length);
- }else if(!(callback instanceof Function)){
- return __exec(pDb, sql, callback, pVoid, pErrMsg);
- }
- /* Wrap the callback in a WASM-bound function and convert the callback's
- `(char**)` arguments to arrays of strings... */
- let aNames;
- const cbwrap = function(pVoid, nCols, pColVals, pColNames){
- try {
- const aVals = wasm.cArgvToJs(nCols, pColVals);
- if(!aNames) aNames = wasm.cArgvToJs(nCols, pColNames);
- return callback(aVals, aNames) | 0;
- }catch(e){
- /* If we set the db error state here, the higher-level
- exec() call replaces it with its own, so we have no way
- of reporting the exception message except the console. We
- must not propagate exceptions through the C API. Though
- we make an effort to report OOM here, sqlite3_exec()
- translates that into SQLITE_ABORT as well. */
- return e.resultCode || capi.SQLITE_ERROR;
- }
- };
- let rc;
- try{
- rc = __exec(pDb, sql, cbwrap, pVoid, pErrMsg);
- }catch(e){
- rc = util.sqlite3_wasm_db_error(pDb, capi.SQLITE_ERROR,
- "Error running exec(): "+e);
- }
- return rc;
- };
- }/*sqlite3_exec() proxy*/;
-
{/* Special-case handling of sqlite3_create_function_v2()
and sqlite3_create_window_function(). */
/**
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index 7804c0458..307ab43f5 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -1419,7 +1419,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
wasm.dealloc(pData);
}
};
-
+
if( util.isUIThread() ){
/* Features specific to the main window thread... */