Skip to content

Commit a47222c

Browse files
committed
fix: expose wasm wrapper version at runtime
Register a wasm_version() SQL function backed by SQLITEAI_WASM_WRAPPER_VERSION so generated package versions can be matched by runtime checks. Update the browser version smoke test to include the wasm wrapper segment between SQLite and module versions.
1 parent e1b60ca commit a47222c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

sqlite-wasm/test/demo.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
testString += version;
2222
},
2323
});
24+
db.exec({
25+
sql: 'select wasm_version();',
26+
rowMode: 'array',
27+
callback: function (version) {
28+
testString += `-wasm.${version}`;
29+
},
30+
});
2431
db.exec({
2532
sql: 'select cloudsync_version();',
2633
rowMode: 'array',

wasm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,22 @@ void dbmem_remote_engine_free (dbmem_remote_engine_t *engine) {
766766

767767
// MARK: -
768768

769+
static void sqliteai_wasm_version(sqlite3_context *context, int argc, sqlite3_value **argv) {
770+
(void)argc;
771+
(void)argv;
772+
sqlite3_result_text(context, SQLITEAI_WASM_WRAPPER_VERSION, -1, SQLITE_STATIC);
773+
}
774+
775+
static int sqlite3_wasm_wrapper_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) {
776+
(void)pzErrMsg;
777+
(void)pApi;
778+
return sqlite3_create_function(db, "wasm_version", 0, SQLITE_UTF8 | SQLITE_DETERMINISTIC, NULL, sqliteai_wasm_version, NULL, NULL);
779+
}
780+
769781
int sqlite3_wasm_extra_init(const char *z) {
770782
fprintf(stderr, "%s: %s()\n", __FILE__, __func__);
771783
int rc = SQLITE_OK;
784+
rc = sqlite3_auto_extension((void *) sqlite3_wasm_wrapper_init);
772785
rc = sqlite3_auto_extension((void *) sqlite3_cloudsync_init);
773786
rc = sqlite3_auto_extension((void *) sqlite3_vector_init);
774787
rc = sqlite3_auto_extension((void *) sqlite3_memory_init);

0 commit comments

Comments
 (0)