diff options
author | stephan <stephan@noemail.net> | 2022-12-23 19:16:45 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-23 19:16:45 +0000 |
commit | 3705f38ab0a22187fd019e431c280cb82eca1165 (patch) | |
tree | af29877503a18fdd53d84e7ffdf6338acf3130cf /ext/wasm/api/sqlite3-api-glue.js | |
parent | 19d14f9717f0289a630f23c4b10e7ac2604bea4d (diff) | |
download | sqlite-3705f38ab0a22187fd019e431c280cb82eca1165.tar.gz sqlite-3705f38ab0a22187fd019e431c280cb82eca1165.zip |
Consolidate/unify how the JS bindings of the create_function/collation family of functions react to a non-UTF8 encoding: they now treat a falsy value as SQLITE_UTF8 and fail with SQLITE_FORMAT for an invalid encoding.
FossilOrigin-Name: deffe6fb211410fa1a1fbca824a52b4e09b54d4b4f4a4e12d71c9e4b7e8606fb
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-glue.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 59b40786e..f1f93da73 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -460,6 +460,15 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ (1===n?"":'s')+"."); }; + /** Code duplication reducer for functions which take an encoding + argument and require SQLITE_UTF8. Sets the db error code to + SQLITE_FORMAT and returns that code. */ + const __errEncoding = (pDb)=>{ + return util.sqlite3_wasm_db_error( + pDb, capi.SQLITE_FORMAT, "SQLITE_UTF8 is the only supported encoding." + ); + }; + if(1){/* Bindings for sqlite3_create_collation() */ const __collationContextKey = (argIndex,argv)=>{ @@ -495,7 +504,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ them. 2) It returns capi.SQLITE_FORMAT if the 3rd argument is not - capi.SQLITE_UTF8. No other encodings are supported. + capi.SQLITE_UTF8. No other encodings are supported. To simplify + usage, any falsy value of eTextRep is treated as SQLITE_UTF8. Returns 0 on success, non-0 on error, in which case the error state of pDb (of type `sqlite3*` or argument-convertible to it) @@ -503,10 +513,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ capi.sqlite3_create_collation_v2 = function(pDb,zName,eTextRep,pArg,xCompare,xDestroy){ if(6!==arguments.length) return __dbArgcMismatch(pDb, 'sqlite3_create_collation_v2', 6); - else if(capi.SQLITE_UTF8!==eTextRep){ - return util.sqlite3_wasm_db_error( - pDb, capi.SQLITE_FORMAT, "SQLITE_UTF8 is the only supported encoding." - ); + else if(!eTextRep){ + eTextRep = capi.SQLITE_UTF8; + }else if(capi.SQLITE_UTF8!==eTextRep){ + return __errEncoding(pDb); } let rc, pfCompare, pfDestroy; try{ @@ -580,6 +590,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ "int"/*eTextRep*/, "*"/*pApp*/, "*"/*xStep*/,"*"/*xFinal*/, "*"/*xValue*/, "*"/*xDestroy*/] ); + // TODO: reimplement these using FuncPtrAdapter. const sqlite3CreateWindowFunction = wasm.xWrap( "sqlite3_create_window_function", "int", ["sqlite3*", "string"/*funcName*/, "int"/*nArg*/, @@ -657,6 +668,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ){ if(f.length!==arguments.length){ return __dbArgcMismatch(pDb,"sqlite3_create_function_v2",f.length); + }else if(!eTextRep){ + eTextRep = capi.SQLITE_UTF8; + }else if(capi.SQLITE_UTF8!==eTextRep){ + return __errEncoding(pDb); } /* Wrap the callbacks in a WASM-bound functions... */ const uninstall = [/*funcs to uninstall on error*/]; @@ -698,6 +713,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ){ if(f.length!==arguments.length){ return __dbArgcMismatch(pDb,"sqlite3_create_window_function",f.length); + }else if(!eTextRep){ + eTextRep = capi.SQLITE_UTF8; + }else if(capi.SQLITE_UTF8!==eTextRep){ + return __errEncoding(pDb); } /* Wrap the callbacks in a WASM-bound functions... */ const uninstall = [/*funcs to uninstall on error*/]; |