Skip to content

Commit 6a20a45

Browse files
author
Christopher J. Brody
committed
add custom_extensions function in a new module
for custom (non-standard) SQLite3 extension functions that may be added in the future with some additional explanatory comments added to the CoffeeScript
1 parent 091395f commit 6a20a45

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

Diff for: Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ EMFLAGS_DEBUG = \
5858
-s ASSERTIONS=1 \
5959
-O1
6060

61-
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
61+
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc out/custom_extensions.bc
6262

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

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

163+
out/custom_extensions.bc: src/custom_extensions/custom_extensions.c
164+
mkdir -p out
165+
$(EMCC) $(CFLAGS) -Isqlite-src/$(SQLITE_AMALGAMATION) -s LINKABLE=1 $^ -o $@
166+
163167
# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
164168
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
165169
# tar --create --gzip $^ > $@

Diff for: src/api.coffee

+6
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,13 @@ class Database
240240
constructor: (data) ->
241241
@filename = 'dbfile_' + (0xffffffff*Math.random()>>>0)
242242
if data? then FS.createDataFile '/', @filename, data, true, true
243+
# open the database and register extension functions
243244
@handleError sqlite3_open @filename, apiTemp
244245
@db = getValue(apiTemp, 'i32')
246+
# register built-in extension functions:
245247
RegisterExtensionFunctions(@db)
248+
# register any custom (non-standard) extension functions:
249+
custom_extensions(@db)
246250
@statements = {} # A list of all prepared statements of the database
247251
@functions = {} # A list of all user function of the database (created by create_function call)
248252

@@ -404,6 +408,8 @@ class Database
404408
@functions={}
405409
@handleError sqlite3_close_v2 @db
406410
binaryDb = FS.readFile @filename, encoding:'binary'
411+
# just open the database
412+
# (no need to register extension functions)
407413
@handleError sqlite3_open @filename, apiTemp
408414
@db = getValue apiTemp, 'i32'
409415
binaryDb

Diff for: src/custom_extensions/custom_extensions.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "sqlite3.h"
2+
3+
/** FUTURE TBD Build this module with any custom extension module(s) included */
4+
5+
int custom_extensions(sqlite3 * db)
6+
{
7+
return SQLITE_OK;
8+
}

Diff for: src/exported_functions.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
"_sqlite3_result_int",
3939
"_sqlite3_result_int64",
4040
"_sqlite3_result_error",
41+
"_custom_extensions",
4142
"_RegisterExtensionFunctions"
4243
]

Diff for: src/exports.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ sqlite3_result_int64 = Module['cwrap'] 'sqlite3_result_int64', '', ['number', 'n
5959
sqlite3_result_error = Module['cwrap'] 'sqlite3_result_error', '', ['number', 'string', 'number']
6060
RegisterExtensionFunctions = Module['cwrap'] 'RegisterExtensionFunctions', 'number', ['number']
6161

62+
## Support custom db extensions
63+
custom_extensions = Module['cwrap'] 'custom_extensions', 'number', ['number']
64+
6265
# Export the API
6366
this['SQL'] = {'Database':Database}
6467
Module[i] = this['SQL'][i] for i of this['SQL']

0 commit comments

Comments
 (0)