1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

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
This commit is contained in:
stephan
2022-12-23 19:16:45 +00:00
parent 19d14f9717
commit 3705f38ab0
4 changed files with 47 additions and 15 deletions

View File

@ -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*/];