Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Custom Extensions to sql.js #459

Closed
twoxfh opened this issue Jun 2, 2021 · 3 comments
Closed

Adding Custom Extensions to sql.js #459

twoxfh opened this issue Jun 2, 2021 · 3 comments

Comments

@twoxfh
Copy link

twoxfh commented Jun 2, 2021

Great project, I am using @Taytay development environment which makes it super easy to build sql.js. I am trying to add extensions from ext/misc such as series into sql.js. I added series.c to the sqlite-src/sqlite-amalgamation folder and modified the Makefile:

out/series.bc: sqlite-src/$(SQLITE_AMALGAMATION)
 	mkdir -p out
 	$(EMCC) $(CFLAGS) -s LINKABLE=1 -c sqlite-src/$(SQLITE_AMALGAMATION)/series.c -o $@

and

BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc out/series.bc

This successfully compiles, but I cannot run query on SQLite, SELECT value FROM generate_series(5,100,5) it says the generate_series doesnt exist. I also added "_sqlite3_series_init" to exported_functions, however, that did not change anything,

Can anyone shed some light on adding custom extensions?

@kaizhu256
Copy link
Member

maybe delete the OMIT_LOAD_EXTENSION flag? was added in commit 8aed8927, i'm guessing to reduce filesize

diff --git a/Makefile b/Makefile
index 9aeed3b..2038f86 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,6 @@ EMCC=emcc

 CFLAGS = \
        -O2 \
-       -DSQLITE_OMIT_LOAD_EXTENSION \
        -DSQLITE_DISABLE_LFS \
        -DSQLITE_ENABLE_FTS3 \
        -DSQLITE_ENABLE_FTS3_PARENTHESIS \

@rhashimoto
Copy link

I think SQLITE_OMIT_LOAD_EXTENSION is for dynamically loaded extensions, and the OP is trying to add an extension statically.

My guess is they need to call the extension initialization function, just as the standard extensions initialization function is exported (as already done), wrapped, and called.

@twoxfh
Copy link
Author

twoxfh commented Jun 2, 2021

@rhashimoto @kaizhu256 thanks for your feedback! @rhashimoto read my mind, and it works. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants