Skip to content

Commit e316007

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 e810a2c commit e316007

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ EMFLAGS_DEBUG = \
5151
-s ASSERTIONS=1 \
5252
-O1
5353

54-
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
54+
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc out/custom_extensions.bc
55+
5556
OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js
5657

5758
all: optimized debug worker
@@ -145,6 +146,10 @@ out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTI
145146
mkdir -p out
146147
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
147148

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

src/api.coffee

Lines changed: 6 additions & 0 deletions
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
Lines changed: 8 additions & 0 deletions
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+
}

src/exported_functions.json

Lines changed: 1 addition & 0 deletions
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
]

src/exports.coffee

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy