Skip to content

Commit

Permalink
only load our extension into dbs created from JS
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Aug 9, 2023
1 parent 8f5f47c commit de2c345
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ WASQLITE_DEFINES ?= \
-DSQLITE_ENABLE_BYTECODE_VTAB \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_USE_ALLOCA \
-DSQLITE_EXTRA_INIT=core_init \
-DSQLITE_ENABLE_BATCH_ATOMIC_WRITE \
-DSQLITE_ENABLE_FTS5 \
-DCRSQLITE_WASM
Expand Down
4 changes: 3 additions & 1 deletion src/exported_functions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"_RegisterExtensionFunctions",
"_core_init",
"_main",
"_malloc",
"_free",
Expand Down Expand Up @@ -53,5 +54,6 @@
"_sqlite3_value_int64",
"_sqlite3_value_text",
"_sqlite3_value_type",
"_sqlite3_vfs_find"
"_sqlite3_vfs_find",
"_sqlite3_reset_auto_extension"
]
4 changes: 4 additions & 0 deletions src/sqlite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ export function Factory(Module) {
})();

sqlite3.open_v2 = (function() {
// setup auto-extension loading
Module.ccall('core_init', 'void', ['number'], [0]);
const fname = 'sqlite3_open_v2';
const f = Module.cwrap(fname, ...decl('snnn:n'), { async });
return async function(zFilename, flags, zVfs) {
Expand All @@ -518,6 +520,8 @@ export function Factory(Module) {
Module._sqlite3_free(zVfs);

Module.ccall('RegisterExtensionFunctions', 'void', ['number'], [db]);
// tear it back down so temp dbs created by the extension (e.g., for automigrate) don't get the extension
Module.ccall('sqlite3_reset_auto_extension', 'void');
check(fname, result);
return db;
};
Expand Down

0 comments on commit de2c345

Please sign in to comment.