1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Add sqlite3.capi JS bindings for the sqlite3session_...(), sqlite3changeset_...() and sqlite3changegroup_...() APIs, noting that they are completely untested. Aside from missing tests, these bindings reveal a slight string-argument-type shortcoming in the callback function pointer "reverse binding" which should ideally be resolved before publishing them.

FossilOrigin-Name: 0a39172ee134816f5ce17a403b960e9c22bb56efd5bcf77ecde465efe0d88b1d
This commit is contained in:
stephan
2022-12-23 14:11:54 +00:00
parent cc1cc9d7b7
commit 0f29f17bf6
6 changed files with 249 additions and 29 deletions

View File

@ -184,6 +184,7 @@ _sqlite3session_enable
_sqlite3session_indirect
_sqlite3session_isempty
_sqlite3session_memory_used
_sqlite3session_object_config
_sqlite3session_patchset
_sqlite3session_patchset_strm
_sqlite3session_table_filter

View File

@ -59,10 +59,16 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
the lines of sqlite3_prepare_v3(). The slightly problematic
part is the final argument (text destructor). */
],
//["sqlite3_busy_handler","int", "sqlite3*", "*", "*"],
// ^^^^ TODO: custom binding which auto-converts JS function arg
// to a WASM function, noting that calling it multiple times
// would introduce a leak.
["sqlite3_busy_handler","int", [
"sqlite3*",
new wasm.xWrap.FuncPtrAdapter({
name: 'sqlite3_busy_handler',
signature: 'i(pi)',
bindScope: 'context',
contextKey: (argIndex,argv)=>'sqlite3@'+argv[0]
}),
"*"
]],
["sqlite3_busy_timeout","int", "sqlite3*", "int"],
["sqlite3_close_v2", "int", "sqlite3*"],
["sqlite3_changes", "int", "sqlite3*"],
@ -131,14 +137,16 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
for those, depending on how their SQL argument is provided. */
/* sqlite3_randomness() uses a hand-written wrapper to extend
the range of supported argument types. */
[
[
"sqlite3_progress_handler", undefined, [
"sqlite3*", "int", new wasm.xWrap.FuncPtrAdapter({
"sqlite3*", "int",
new wasm.xWrap.FuncPtrAdapter({
name: 'xProgressHandler',
signature: 'i(p)',
bindScope: 'context',
contextKey: (argIndex,argv)=>'sqlite3@'+argv[0]
}), "*"
}),
"*"
]
],
["sqlite3_realloc", "*","*","int"],
@ -211,7 +219,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
optional features into account. */
wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
}
/**
Functions which require BigInt (int64) support are separated from
the others because we need to conditionally bind them or apply
@ -263,6 +271,187 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
["sqlite3_vtab_rhs_value","int", "sqlite3_index_info*", "int", "**"]
];
// Add session/changeset APIs...
if(wasm.bigIntEnabled && !!wasm.exports.sqlite3changegroup_add){
/* ACHTUNG: 2022-12-23: the session/changeset API bindings are
COMPLETELY UNTESTED. Additionally, the callback-taking APIs
have a shortcoming which will make using those which take
string-type arguments more painful than it should be. How best
to resolve that, such that we can perform the same type conversions
as we do when binding in "the other direction," is as yet
undetermined.
*/
/* TODO: we need hand-written wrappers to adapt callbacks which
take string arguments. Or we need to find a way to do this sort
of reverse-binding which includes type conversions. */
wasm.bindingSignatures.int64.push(...[
['sqlite3changegroup_add', 'int', ['sqlite3_changegroup*', 'int', 'void*']],
['sqlite3changegroup_add_strm', 'int', [
'sqlite3_changegroup*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changegroup_delete', undefined, ['sqlite3_changegroup*']],
['sqlite3changegroup_new', 'int', ['**']],
['sqlite3changegroup_output', 'int', ['sqlite3_changegroup*', 'int*', '**']],
['sqlite3changegroup_output_strm', 'int', [
'sqlite3_changegroup*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xOutput', signature: 'i(ppi)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_apply', 'int', [
'sqlite3*', 'int', 'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)', bindScope: 'transient'
}),
new wasm.xWrap.FuncPtrAdapter({
name: 'xConflict', signature: 'i(pip)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_apply_strm', 'int', [
'sqlite3*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)', bindScope: 'transient'
}),
new wasm.xWrap.FuncPtrAdapter({
name: 'xConflict', signature: 'i(pip)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_apply_v2', 'int', [
'sqlite3*', 'int', 'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)', bindScope: 'transient'
}),
new wasm.xWrap.FuncPtrAdapter({
name: 'xConflict', signature: 'i(pip)', bindScope: 'transient'
}),
'void*', '**', 'int*', 'int'
]],
['sqlite3changeset_apply_v2', 'int', [
'sqlite3*', 'int', 'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)', bindScope: 'transient'
}),
new wasm.xWrap.FuncPtrAdapter({
name: 'xConflict', signature: 'i(pip)', bindScope: 'transient'
}),
'void*', '**', 'int*', 'int'
]],
['sqlite3changeset_apply_v2_strm', 'int', [
'sqlite3*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)', bindScope: 'transient'
}),
new wasm.xWrap.FuncPtrAdapter({
name: 'xConflict', signature: 'i(pip)', bindScope: 'transient'
}),
'void*', '**', 'int*', 'int'
]],
['sqlite3changeset_concat', 'int', ['int','void*', 'int', 'void*', 'int*', '**']],
['sqlite3changeset_concat_strm', 'int', [
new wasm.xWrap.FuncPtrAdapter({
name: 'xInputA', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInputB', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xOutput', signature: 'i(ppi)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_conflict', 'int', ['sqlite3_changeset_iter*', 'int', '**']],
['sqlite3changeset_finalize', 'int', ['sqlite3_changeset_iter*']],
['sqlite3changeset_fk_conflicts', 'int', ['sqlite3_changeset_iter*', 'int*']],
['sqlite3changeset_invert', 'int', ['int', 'void*', 'int*', '**']],
['sqlite3changeset_invert_strm', 'int', [
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xOutput', signature: 'i(ppi)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_new', 'int', ['sqlite3_changeset_iter*', 'int', '**']],
['sqlite3changeset_next', 'int', ['sqlite3_changeset_iter*']],
['sqlite3changeset_old', 'int', ['sqlite3_changeset_iter*', 'int', '**']],
['sqlite3changeset_op', 'int', [
'sqlite3_changeset_iter*', '**', 'int*', 'int*','int*'
]],
['sqlite3changeset_pk', 'int', ['sqlite3_changeset_iter*', '**', 'int*']],
['sqlite3changeset_start', 'int', ['**', 'int', '*']],
['sqlite3changeset_start_strm', 'int', [
'**',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3changeset_start_v2', 'int', ['**', 'int', '*', 'int']],
['sqlite3changeset_start_v2_strm', 'int', [
'**',
new wasm.xWrap.FuncPtrAdapter({
name: 'xInput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*', 'int'
]],
['sqlite3session_attach', 'int', ['sqlite3_session*', 'string']],
['sqlite3session_changeset', 'int', ['sqlite3_session*', 'int*', '**']],
['sqlite3session_changeset_size', 'i64', ['sqlite3_session*']],
['sqlite3session_changeset_strm', 'int', [
'sqlite3_session*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xOutput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3session_config', 'int', ['int', 'void*']],
['sqlite3session_create', 'int', ['sqlite3*', 'string', '**']],
['sqlite3session_delete', undefined, ['sqlite3_session*']],
['sqlite3session_diff', 'int', ['sqlite3_session*', 'string', 'string', '**']],
['sqlite3session_enable', 'int', ['sqlite3_session*', 'int']],
['sqlite3session_indirect', 'int', ['sqlite3_session*', 'int']],
['sqlite3session_isempty', 'int', ['sqlite3_session*']],
['sqlite3session_memory_used', 'i64', ['sqlite3_session*']],
['sqlite3session_object_config', 'int', ['sqlite3_session*', 'int', 'void*']],
['sqlite3session_patchset', 'int', ['sqlite3_session*', '*', '**']],
['sqlite3session_patchset_strm', 'int', [
'sqlite3_session*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xOutput', signature: 'i(ppp)', bindScope: 'transient'
}),
'void*'
]],
['sqlite3session_table_filter', undefined, [
'sqlite3_session*',
new wasm.xWrap.FuncPtrAdapter({
name: 'xFilter', signature: 'i(ps)',
contextKey: (argIndex,argv)=>argv[0/* (sqlite3_session*) */]
}),
'*'
]]
]);
}/*session/changeset APIs*/
/**
Functions which are intended solely for API-internal use by the
WASM components, not client code. These get installed into
@ -513,7 +702,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
);
}
let rc, pfCompare, pfDestroy;
try{
try{
rc = __ccv2(pDb, zName, eTextRep, pArg, xCompare, xDestroy);
}catch(e){
rc = util.sqlite3_wasm_db_error(pDb, e);
@ -910,12 +1099,14 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
wasm.ctype = JSON.parse(wasm.cstrToJs(cJson));
//console.debug('wasm.ctype length =',wasm.cstrlen(cJson));
const defineGroups = ['access', 'authorizer',
'blobFinalizers', 'config', 'dataTypes',
'blobFinalizers', 'changeset',
'config', 'dataTypes',
'dbConfig', 'dbStatus',
'encodings', 'fcntl', 'flock', 'ioCap',
'limits', 'openFlags',
'prepareFlags', 'resultCodes',
'serialize', 'sqlite3Status',
'serialize', 'session',
'sqlite3Status',
'stmtStatus', 'syncFlags',
'trace', 'txnState', 'udfFlags',
'version' ];

View File

@ -461,6 +461,22 @@ const char * sqlite3_wasm_enum_json(void){
out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
} _DefGroup;
DefGroup(changeset){
DefInt(SQLITE_CHANGESETSTART_INVERT);
DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT);
DefInt(SQLITE_CHANGESETAPPLY_INVERT);
DefInt(SQLITE_CHANGESET_DATA);
DefInt(SQLITE_CHANGESET_NOTFOUND);
DefInt(SQLITE_CHANGESET_CONFLICT);
DefInt(SQLITE_CHANGESET_CONSTRAINT);
DefInt(SQLITE_CHANGESET_FOREIGN_KEY);
DefInt(SQLITE_CHANGESET_OMIT);
DefInt(SQLITE_CHANGESET_REPLACE);
DefInt(SQLITE_CHANGESET_ABORT);
} _DefGroup;
DefGroup(config){
DefInt(SQLITE_CONFIG_SINGLETHREAD);
DefInt(SQLITE_CONFIG_MULTITHREAD);
@ -797,6 +813,11 @@ const char * sqlite3_wasm_enum_json(void){
DefInt(SQLITE_DESERIALIZE_RESIZEABLE);
} _DefGroup;
DefGroup(session){
DefInt(SQLITE_SESSION_CONFIG_STRMSIZE);
DefInt(SQLITE_SESSION_OBJCONFIG_SIZE);
} _DefGroup;
DefGroup(sqlite3Status){
DefInt(SQLITE_STATUS_MEMORY_USED);
DefInt(SQLITE_STATUS_PAGECACHE_USED);

View File

@ -446,7 +446,7 @@ self.WhWasmUtilInstaller = function(target){
type(s) of the given function signature, or throws if the
signature is invalid. */
/******** // only valid for use with the WebAssembly.Function ctor, which
// is not yet documented on MDN.
// is not yet documented on MDN.
sigToWasm: function(sig){
const rc = {parameters:[], results: []};
if('v'!==sig[0]) rc.results.push(f.sigTypes(sig[0]));
@ -1581,10 +1581,20 @@ self.WhWasmUtilInstaller = function(target){
not actually bind any functions. Its convertArg() method is
called via xWrap() to perform any bindings.
Shortcomings: function pointers which include C-string arguments
may still need a level of hand-written wrappers around them,
depending on how they're used, in order to provide the client
with JS strings.
Shortcomings:
- These "reverse" bindings, i.e. calling into a JS-defined
function from a WASM-defined function (the generated proxy
wrapper), lack all type conversion support. That means, for
example, that...
- Function pointers which include C-string arguments may still
need a level of hand-written wrappers around them, depending on
how they're used, in order to provide the client with JS
strings. Alternately, clients will need to perform such conversions
on their own, e.g. using cstrtojs(). Or maybe we can find a way
to perform such conversions here, via addition of an xWrap()-style
function signature to the options argument.
*/
xArg.FuncPtrAdapter = class FuncPtrAdapter extends AbstractArgAdapter {
constructor(opt) {

View File

@ -1,5 +1,5 @@
C Initial\spieces\sfor\sbinding\sthe\ssession\sAPI\sto\sJS.\sFar\sfrom\scomplete.\sSee\s[forum:210e36a1e3\s|\sforum\spost\s210e36a1e3]\sfor\sthe\sdiscussion.
D 2022-12-23T11:46:26.185
C Add\ssqlite3.capi\sJS\sbindings\sfor\sthe\ssqlite3session_...(),\ssqlite3changeset_...()\sand\ssqlite3changegroup_...()\sAPIs,\snoting\sthat\sthey\sare\scompletely\suntested.\sAside\sfrom\smissing\stests,\sthese\sbindings\sreveal\sa\sslight\sstring-argument-type\sshortcoming\sin\sthe\scallback\sfunction\spointer\s"reverse\sbinding"\swhich\sshould\sideally\sbe\sresolved\sbefore\spublishing\sthem.
D 2022-12-23T14:11:54.508
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -494,7 +494,7 @@ F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34ce
F ext/wasm/GNUmakefile 06d385b51bfb206cf779cf1bb816862f77df97fff97a6df9baf05b98c027067a
F ext/wasm/README-dist.txt 2d670b426fc7c613b90a7d2f2b05b433088fe65181abead970980f0a4a75ea20
F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api ff6f8c477f6f38457bce1c604ac517ecc3dfea64f816dc90356c0402f96725b8
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 8c15a035ca5263659f21a691d701e23294621a24d1e130fa8905a261b495ebe4
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
F ext/wasm/api/README.md 77a2f1f2fc60a35def7455dffc8d3f2c56385d6ac5c6cecc60fa938252ea2c54
F ext/wasm/api/extern-post-js.c-pp.js 8923f76c3d2213159e12d641dc750523ead5c848185dc4996fae5cc12397f88d
@ -503,7 +503,7 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08
F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62
F ext/wasm/api/pre-js.c-pp.js b88499dc303c21fc3f55f2c364a0f814f587b60a95784303881169f9e91c1d5f
F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4
F ext/wasm/api/sqlite3-api-glue.js dfdfbcdf1a9d4e42836ec53fda02c70869cfe5651a75e785b62ff69c4fe822e2
F ext/wasm/api/sqlite3-api-glue.js 5a28c384ece2066522cf8b04a454d44c0245835a6a26b681d3deed97b3805623
F ext/wasm/api/sqlite3-api-oo1.js c0c4ccc269cccee657ffd03f094da7e270e1367b7928926b3730d543555a12a6
F ext/wasm/api/sqlite3-api-prologue.js 1767dfcd94bb4fa9dd4bd9ff6327117783d3656faf1058dcc1369db320d871fc
F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f
@ -512,7 +512,7 @@ F ext/wasm/api/sqlite3-opfs-async-proxy.js 7795b84b66a7a8dedc791340709b310bb497c
F ext/wasm/api/sqlite3-v-helper.js 6f6c3e390a72e08b0a5b16a0d567d7af3c04d172831853a29d72a6f1dd40ff24
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 66daf6fb6843bea615fe193109e1542efbeca24f560ee9da63375a910bb48115
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
F ext/wasm/api/sqlite3-wasm.c 15194e3d5e0bcbcdcafb928392438d83aed56bdb8e71984ac415cc6a3b75e602
F ext/wasm/api/sqlite3-wasm.c f0aafd3e8f09c68bec14bd0cc7a31212964302134dec8c428e7afc517e78e257
F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b
F ext/wasm/api/sqlite3-worker1.js 1e54ea3d540161bcfb2100368a2fc0cad871a207b8336afee1c445715851ec54
F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8
@ -521,7 +521,7 @@ F ext/wasm/c-pp.c 92285f7bce67ed7b7020b40fde8ed0982c442b63dc33df9dfd4b658d4a6c07
F ext/wasm/common/SqliteTestUtil.js d8bf97ecb0705a2299765c8fc9e11b1a5ac7f10988bbf375a6558b7ca287067b
F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15
F ext/wasm/common/testing.css 0ff15602a3ab2bad8aef2c3bd120c7ee3fd1c2054ad2ace7e214187ae68d926f
F ext/wasm/common/whwasmutil.js ba1a8db1f32124e43e24b3d890102b6552b2c0b5a202185041a55887692df328
F ext/wasm/common/whwasmutil.js af85d9a09fa79847d08279be0f61978ecc3bed893c88003f4a85d8bd204e6b5a
F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6
@ -2067,11 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P a02e19dd6ce00492f3d187e3c3c9bde4d9d1ee9a23616e62ea3590eec95652bd
R 754103df3bb98463a7b36626ed444e4f
T *branch * wasm-session-api
T *sym-wasm-session-api *
T -sym-trunk * Cancelled\sby\sbranch.
P cd8c100808da1043fcf63555f48f30c90272c48c6627321ceb0a0995b34733d1
R 042a575edf17a004d3f3655705629da7
U stephan
Z bbc6e7158315d4288a4f21a6ce2dd790
Z 81bf3460fe50c1e6a01aac07ed8bed30
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
cd8c100808da1043fcf63555f48f30c90272c48c6627321ceb0a0995b34733d1
0a39172ee134816f5ce17a403b960e9c22bb56efd5bcf77ecde465efe0d88b1d