aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-glue.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-23 19:33:22 +0000
committerstephan <stephan@noemail.net>2022-12-23 19:33:22 +0000
commit77eac0507c7f36a50814336fb1da6a5c3923ffec (patch)
tree8011d103173334c018a71d606342614d743c1990 /ext/wasm/api/sqlite3-api-glue.js
parentb5915699d0404bcd3b502e18af3d889d0bf581dc (diff)
parent3705f38ab0a22187fd019e431c280cb82eca1165 (diff)
downloadsqlite-77eac0507c7f36a50814336fb1da6a5c3923ffec.tar.gz
sqlite-77eac0507c7f36a50814336fb1da6a5c3923ffec.zip
Merge trunk into wasm-session-api branch.
FossilOrigin-Name: f1decc831fe0dc8523956e74474d9663852b0e5b56240dd8504952726e713a97
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-glue.js29
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 dc1e827d5..f5a6c5753 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -653,6 +653,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)=>{
@@ -688,7 +697,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)
@@ -696,10 +706,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{
@@ -773,6 +783,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*/,
@@ -850,6 +861,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*/];
@@ -891,6 +906,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*/];