diff --git a/Makefile b/Makefile index bccfed23..02867861 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,8 @@ 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 all: optimized debug worker @@ -145,6 +146,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 $^ > $@ diff --git a/src/api.coffee b/src/api.coffee index f11ea80e..5a5f63bd 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -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) @@ -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 diff --git a/src/custom_extensions/custom_extensions.c b/src/custom_extensions/custom_extensions.c new file mode 100644 index 00000000..2b2585a5 --- /dev/null +++ b/src/custom_extensions/custom_extensions.c @@ -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; +} diff --git a/src/exported_functions.json b/src/exported_functions.json index af5085c7..4db4927f 100644 --- a/src/exported_functions.json +++ b/src/exported_functions.json @@ -38,5 +38,6 @@ "_sqlite3_result_int", "_sqlite3_result_int64", "_sqlite3_result_error", +"_custom_extensions", "_RegisterExtensionFunctions" ] diff --git a/src/exports.coffee b/src/exports.coffee index 6a5a0afa..65acb16f 100644 --- a/src/exports.coffee +++ b/src/exports.coffee @@ -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']