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

[RFC] support build with custom (non-standard) functions #320

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ EMFLAGS_DEBUG = \
-s ASSERTIONS=1 \
-O1

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

OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js

Expand Down Expand Up @@ -160,6 +160,10 @@ out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTI
mkdir -p out
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@

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

# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
# tar --create --gzip $^ > $@
Expand Down
6 changes: 6 additions & 0 deletions src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ class Database
constructor: (data) ->
@filename = 'dbfile_' + (0xffffffff*Math.random()>>>0)
if data? then FS.createDataFile '/', @filename, data, true, true
# open the database and register extension functions
@handleError sqlite3_open @filename, apiTemp
@db = getValue(apiTemp, 'i32')
# register built-in extension functions:
RegisterExtensionFunctions(@db)
# register any custom (non-standard) extension functions:
custom_extensions(@db)
@statements = {} # A list of all prepared statements of the database
@functions = {} # A list of all user function of the database (created by create_function call)

Expand Down Expand Up @@ -404,6 +408,8 @@ class Database
@functions={}
@handleError sqlite3_close_v2 @db
binaryDb = FS.readFile @filename, encoding:'binary'
# just open the database
# (no need to register extension functions)
@handleError sqlite3_open @filename, apiTemp
@db = getValue apiTemp, 'i32'
binaryDb
Expand Down
8 changes: 8 additions & 0 deletions src/custom_extensions/custom_extensions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "sqlite3.h"

/** FUTURE TBD Build this module with any custom extension module(s) included */

int custom_extensions(sqlite3 * db)
{
return SQLITE_OK;
}
1 change: 1 addition & 0 deletions src/exported_functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"_sqlite3_result_int",
"_sqlite3_result_int64",
"_sqlite3_result_error",
"_custom_extensions",
"_RegisterExtensionFunctions"
]
3 changes: 3 additions & 0 deletions src/exports.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ sqlite3_result_int64 = Module['cwrap'] 'sqlite3_result_int64', '', ['number', 'n
sqlite3_result_error = Module['cwrap'] 'sqlite3_result_error', '', ['number', 'string', 'number']
RegisterExtensionFunctions = Module['cwrap'] 'RegisterExtensionFunctions', 'number', ['number']

## Support custom db extensions
custom_extensions = Module['cwrap'] 'custom_extensions', 'number', ['number']

# Export the API
this['SQL'] = {'Database':Database}
Module[i] = this['SQL'][i] for i of this['SQL']