Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch wasm-fts5 Excluding Merge-Ins
This is equivalent to a diff from ea0b9aecba to ce2a65d80f
2023-08-04
| ||
08:39 | More work towards fts5 customzation in JS. (Leaf check-in: ce2a65d80f user: stephan tags: wasm-fts5) | |
2023-08-03
| ||
22:43 | Minor internal cleanups in the JS-side fts5 cleanup steps. (check-in: 2666f52e88 user: stephan tags: wasm-fts5) | |
12:41 | Unix builds now assume the presence of nanosleep() in the standard library. The -DHAVE_NANOSLEEP=0 compile-time option can be used to build on systems (if any still exist) where this is not the case. (check-in: 779d5dc879 user: drh tags: trunk) | |
07:20 | Initial work on exposing the FTS5 APIs to wasm, per request in the forum. This builds and loads the structs into JS but is completely untested. (check-in: 52c8b73ae3 user: stephan tags: wasm-fts5) | |
2023-08-02
| ||
18:20 | If a query has an ORDER BY clause that only refers to result columns of the left-most table and the left most table is a MATERIALIZED common table expresion, then attempt to push the ORDER BY clause down into the subquery. (Leaf check-in: 8e7a70b2bb user: drh tags: order-by-push-down) | |
16:06 | Performance optimization for JSON rendering logic. (check-in: ea0b9aecba user: drh tags: trunk) | |
13:45 | Remove an unreachable branch in the ascii-to-floating-point conversion that was added by [e989a37ff9d5b52e]. (check-in: c4347e4400 user: drh tags: trunk) | |
Changes to ext/wasm/GNUmakefile.
︙ | |||
345 346 347 348 349 350 351 352 353 354 355 356 357 358 | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | + + + + + + | # EXPORTED_FUNCTIONS.* = files for use with Emscripten's # -sEXPORTED_FUNCTION flag. EXPORTED_FUNCTIONS.api.main := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api) EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.main) ifeq (1,$(SQLITE_C_IS_SEE)) EXPORTED_FUNCTIONS.api.in += $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see) endif ifeq (1,$(emcc.WASM_BIGINT)) ifneq (,$(filter -DSQLITE_ENABLE_FTS5,$(SQLITE_OPT))) EXPORTED_FUNCTIONS.api.in += $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-fts5) endif endif EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api $(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) cat $(EXPORTED_FUNCTIONS.api.in) > $@ # sqlite3-license-version.js = generated JS file with the license # header and version info. sqlite3-license-version.js := $(dir.tmp)/sqlite3-license-version.js |
︙ | |||
371 372 373 374 375 376 377 378 379 380 381 382 383 384 | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | + + + | sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js sqlite3-api.jses += $(sqlite3-api-build-version.js) sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js sqlite3-api.jses += $(dir.api)/sqlite3-v-helper.js sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js ifneq (,$(filter -DSQLITE_ENABLE_FTS5,$(SQLITE_OPT))) sqlite3-api.jses += $(dir.api)/sqlite3-fts5-helper.js endif sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js # SOAP.js is an external API file which is part of our distribution # but not part of the sqlite3-api.js amalgamation. SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js SOAP.js.bld := $(dir.dout)/$(notdir $(SOAP.js)) sqlite3-api.ext.jses += $(SOAP.js.bld) |
︙ |
Added ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-fts5.
1 | + | _fts5_api_from_db |
Changes to ext/wasm/api/sqlite3-api-cleanup.js.
︙ | |||
48 49 50 51 52 53 54 | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | - + + | }catch(e){ console.error("sqlite3ApiBootstrap() error:",e); throw e; }finally{ delete globalThis.sqlite3ApiBootstrap; delete globalThis.sqlite3ApiConfig; } |
Changes to ext/wasm/api/sqlite3-api-glue.js.
︙ | |||
257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | + + + + + + + + + + + + | return e.resultCode || capi.SQLITE_ERROR; } } } }), "*"/*pUserData*/ ]], /** Achtung: when specifying an xDestroy() method via sqlite3_set_auxdata(), it is up to the client to re-set it to 0/NULL at the end of its lifetime (e.g. in the associated UDF's xFinal() impl), The C library will be able to call the destructor but _not_ uninstall the temporary WASM-bound proxy function because it does not have enough information to do so. Alternately, clients may create the function pointer themselves using wasm.createFunction() and pass that pointer here, in which case they avoid creating a stranded "temporary" function binding. */ ["sqlite3_set_auxdata", undefined, [ "sqlite3_context*", "int", "*", new wasm.xWrap.FuncPtrAdapter({ name: 'xDestroyAuxData', signature: 'v(*)', contextKey: (argv, argIndex)=>argv[0/* sqlite3_context* */] }) |
︙ | |||
417 418 419 420 421 422 423 | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | - - | ["sqlite3_vtab_nochange","int", "sqlite3_context*"], ["sqlite3_vtab_on_conflict","int", "sqlite3*"], ["sqlite3_vtab_rhs_value","int", "sqlite3_index_info*", "int", "**"] ]; // Add session/changeset APIs... if(wasm.bigIntEnabled && !!wasm.exports.sqlite3changegroup_add){ |
︙ | |||
593 594 595 596 597 598 599 600 601 602 603 604 605 606 | 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | + + + + + + | contextKey: (argv,argIndex)=>argv[0/* (sqlite3_session*) */] }), '*' ]] ]); }/*session/changeset APIs*/ if(wasm.bigIntEnabled && !!wasm.exports.fts5_api_from_db){ wasm.bindingSignatures.int64.push( ['fts5_api_from_db', 'fts5_api*', 'sqlite3*'] ); }/* fts5 APIs */ /** Functions which are intended solely for API-internal use by the WASM components, not client code. These get installed into sqlite3.wasm. Some of them get exposed to clients via variants named sqlite3_js_...(). */ wasm.bindingSignatures.wasm = [ |
︙ | |||
655 656 657 658 659 660 661 | 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | - - + + | need it to. */ wasm.xWrap.argAdapter( 'string:static', function(v){ if(wasm.isPtr(v)) return v; v = ''+v; |
︙ | |||
713 714 715 716 717 718 719 | 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | - + + + | ); } return __xArgPtr((v instanceof (capi.sqlite3_vfs || nilType)) ? v.pointer : v); }); const __xRcPtr = wasm.xWrap.resultAdapter('*'); |
︙ | |||
819 820 821 822 823 824 825 826 827 828 829 830 831 832 | 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | + + + | 'prepareFlags', 'resultCodes', 'sqlite3Status', 'stmtStatus', 'syncFlags', 'trace', 'txnState', 'udfFlags', 'version' ]; if(wasm.bigIntEnabled){ defineGroups.push('serialize', 'session', 'vtab'); if(!!wasm.ctype.fts5){ defineGroups.push('fts5'); } } for(const t of defineGroups){ for(const e of Object.entries(wasm.ctype[t])){ // ^^^ [k,v] there triggers a buggy code transformation via // one of the Emscripten-driven optimizers. capi[e[0]] = e[1]; } |
︙ | |||
902 903 904 905 906 907 908 | 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | - + - + | }; /** __dbCleanupMap is infrastructure for recording registration of UDFs and collations so that sqlite3_close_v2() can clean up any automated JS-to-WASM function conversions installed by those. */ |
︙ | |||
969 970 971 972 973 974 975 976 977 978 979 980 981 982 | 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 | + | The issue being addressed here is covered at: https://sqlite.org/wasm/doc/trunk/api-c-style.md#convert-func-ptr */ __dbCleanupMap.cleanup = function(pDb){ pDb = __argPDb(pDb); //console.warn("db cleanup",pDb); //wasm.xWrap.FuncPtrAdapter.debugFuncInstall = false; /** Installing NULL functions in the C API will remove those bindings. The FuncPtrAdapter which sits between us and the C API will also treat that as an opportunity to wasm.uninstallFunction() any WASM function bindings it has installed for pDb. |
︙ | |||
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | + + + | closeArgs.length = x.length/*==argument count*/ /* recall that undefined entries translate to 0 when passed to WASM. */; try{ capi[name](...closeArgs) } catch(e){ console.warn("close-time call of",name+"(",closeArgs,") threw:",e); } } for(const callback of __dbCleanupMap.extraCallbacks){ callback(pDb); } const m = __dbCleanupMap(pDb, 0); if(!m) return; if(m.collation){ for(const name of m.collation){ try{ capi.sqlite3_create_collation_v2( |
︙ | |||
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 | 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 | + + + + + + + + + + + + + + + + + + - + + + + + + + | arities.clear(); } fmap.clear(); } delete m.udf; delete m.wudf; }/*__dbCleanupMap.cleanup()*/; /** Downstream code, namely sqlite3-fts5-helper.js, should add any custom cleanup handlers to __dbCleanupMap.extraCallbacks. Each function in this array will be called during sqlite3_close_v2() and passed a pointer to the being-destroyed (sqlite3*) object. */ __dbCleanupMap.extraCallbacks = []; /** Downstream code, namely sqlite3-fts5-helper.js, should add any custom cleanup handlers to __dbCleanupMap.postCloseCallbacks. Each function in this array will be called during sqlite3_close_v2(), AFTER the db is closed, and passed a pointer to the being-destroyed (sqlite3*) object. The memory is NOT A VALID OBJECT but its address is still valid as a lookup key. */ __dbCleanupMap.postCloseCallbacks = []; {/* Binding of sqlite3_close_v2() */ const __sqlite3CloseV2 = wasm.xWrap("sqlite3_close_v2", "int", "sqlite3*"); const __xArgDb = wasm.xWrap.argAdapter('sqlite3*'); capi.sqlite3_close_v2 = function(pDb){ if(1!==arguments.length) return __dbArgcMismatch(pDb, 'sqlite3_close_v2', 1); pDb = __xArgDb(pDb); if(pDb){ try{__dbCleanupMap.cleanup(pDb)} catch(e){/*ignored*/} } |
︙ | |||
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 | + + + | +':'+wasm.cstrToJs(argv[1]).toLowerCase() ) }; /** JS proxies for the various sqlite3_create[_window]_function() callbacks, structured in a form usable by wasm.xWrap.FuncPtrAdapter. TODO: explore an API option which more closely resembles the /ext/jni mapping, which is much friendlier at the client level. */ const __cfProxy = Object.assign(Object.create(null), { xInverseAndStep: { signature:'v(pip)', contextKey, callProxy: (callback)=>{ return (pCtx, argc, pArgv)=>{ try{ callback(pCtx, ...capi.sqlite3_values_to_js(argc, pArgv)) } |
︙ | |||
1661 1662 1663 1664 1665 1666 1667 | 1713 1714 1715 1716 1717 1718 1719 1720 | - | /* Worker thread: unregister kvvfs to avoid it being used for anything other than local/sessionStorage. It "can" be used that way but it's not really intended to be. */ capi.sqlite3_vfs_unregister(pKvvfs); } }/*pKvvfs*/ |
Changes to ext/wasm/api/sqlite3-api-prologue.js.
︙ | |||
1641 1642 1643 1644 1645 1646 1647 | 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 | - + + | Curiously: despite ostensibly requiring 8-byte alignment, the pArgv array is parcelled into chunks of 4 bytes (1 pointer each). The values those point to have 8-byte alignment but the individual argv entries do not. */ tgt.push(capi.sqlite3_value_to_js( |
︙ |
Added ext/wasm/api/sqlite3-fts5-helper.js.