Skip to content

Commit 1b62e3d

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 as proposed in: https://github.com/kripken/sql.js/pull/320
1 parent 1ccf814 commit 1b62e3d

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ EMFLAGS_DEBUG = \
6565
-s ASSERTIONS=1 \
6666
-O1
6767

68-
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
68+
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc out/custom_extensions.bc
6969

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

@@ -166,6 +166,10 @@ out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTI
166166
mkdir -p out
167167
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
168168

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
custom build by [@brodybits (Christopher J. Brody)](https://github.com/brodybits) with some updates including:
44

5+
- custom functions: TBD
56
- support FTS4, FTS5, R-Tree, and JSON1
67
- some more OMIT build flags to omit some obsolete SQLite features
78
- `dist/sql-asm-debug.js` now built with `-s ALLOW_MEMORY_GROWTH=1` to allow the allocated memory buffer to grow as needed

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