1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Reimplement sqlite3.capi.sqlite3_close_v2() and sqlite3session_delete() as a hand-written bindings so that they can attempt to clean up certain (potentially) FuncPtrAdapter-installed functions before closing. Correct the create-function family of JS-to-function-pointer automated conversions to include the UDF's arity as part of the mapping's key so that (un)binding a UDF to different functions for different arities works (and add tests confirming it). Correct a broken doc link in module-symbols.html.

FossilOrigin-Name: 60b262ef0f57b162c2566b12e70685a92afb00b441332ea7a6540fcb188cc7af
This commit is contained in:
stephan
2022-12-26 11:13:09 +00:00
parent 3a8fbc0749
commit 20170adf14
6 changed files with 146 additions and 22 deletions

View File

@@ -1629,7 +1629,6 @@ self.sqlite3InitModule = sqlite3InitModule;
////////////////////////////////////////////////////////////////////
.t({
name:'Scalar UDFs',
//predicate: ()=>false,
test: function(sqlite3){
const db = this.db;
db.createFunction("foo",(pCx,a,b)=>a+b);
@@ -1696,6 +1695,45 @@ self.sqlite3InitModule = sqlite3InitModule;
sqlite3.capi.SQLITE_MISUSE === rc,
"For invalid arg count."
);
/* Confirm that we can map and unmap the same function with
multiple arities... */
const fCounts = [0,0];
const fArityCheck = function(pCx){
return ++fCounts[arguments.length-1];
};
//wasm.xWrap.FuncPtrAdapter.debugFuncInstall = true;
rc = capi.sqlite3_create_function_v2(
db, "nary", 0, capi.SQLITE_UTF8, 0, fArityCheck, 0, 0, 0
);
T.assert( 0===rc );
rc = capi.sqlite3_create_function_v2(
db, "nary", 1, capi.SQLITE_UTF8, 0, fArityCheck, 0, 0, 0
);
T.assert( 0===rc );
const sqlFArity0 = "select nary()";
const sqlFArity1 = "select nary(1)";
T.assert( 1 === db.selectValue(sqlFArity0) )
.assert( 1 === fCounts[0] ).assert( 0 === fCounts[1] );
T.assert( 1 === db.selectValue(sqlFArity1) )
.assert( 1 === fCounts[0] ).assert( 1 === fCounts[1] );
capi.sqlite3_create_function_v2(
db, "nary", 0, capi.SQLITE_UTF8, 0, 0, 0, 0, 0
);
T.mustThrowMatching((()=>db.selectValue(sqlFArity0)),
(e)=>((e instanceof sqlite3.SQLite3Error)
&& e.message.indexOf("wrong number of arguments")>0),
"0-arity variant was uninstalled.");
T.assert( 2 === db.selectValue(sqlFArity1) )
.assert( 1 === fCounts[0] ).assert( 2 === fCounts[1] );
capi.sqlite3_create_function_v2(
db, "nary", 1, capi.SQLITE_UTF8, 0, 0, 0, 0, 0
);
T.mustThrowMatching((()=>db.selectValue(sqlFArity1)),
(e)=>((e instanceof sqlite3.SQLite3Error)
&& e.message.indexOf("no such function")>0),
"1-arity variant was uninstalled.");
//wasm.xWrap.FuncPtrAdapter.debugFuncInstall = false;
}
})