Skip to content

Commit 4e91be7

Browse files
committed
Upgrade to Sqlite 3.28.0
Download sqlite on demand when building. Remove old unused static sqlite source files. No longer use keyword "nothing" in examples or tests because it leads to a SQL error. (NOTHING is now a reserved word in Sqlite)
1 parent a85a60a commit 4e91be7

20 files changed

+613307
-803754
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
23+
24+
25+
26+
# Some portions of the Makefile taken from:
27+
Copyright 2017 Ryusei Yamaguchi
28+
29+
Permission is hereby granted, free of charge, to any person obtaining a copy of
30+
this software and associated documentation files (the "Software"), to deal in
31+
the Software without restriction, including without limitation the rights to
32+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
33+
the Software, and to permit persons to whom the Software is furnished to do so,
34+
subject to the following conditions:
35+
36+
The above copyright notice and this permission notice shall be included in all
37+
copies or substantial portions of the Software.
38+
39+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
41+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
42+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
43+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

+60-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Note: Last built with version 1.38.30 of Emscripten
22

33
# TODO: Emit a file showing which version of emcc and SQLite was used to compile the emitted output.
4-
# TODO: Make it easier to use a newer version of Sqlite.
54
# TODO: Create a release on Github with these compiled assets rather than checking them in
65
# TODO: Consider creating different files based on browser vs module usage: https://github.com/vuejs/vue/tree/dev/dist
76

7+
# I got this handy makefile syntax from : https://github.com/mandel59/sqlite-wasm (MIT License) Credited in LICENSE
8+
# To use another version of Sqlite, visit https://www.sqlite.org/download.html and copy the appropriate values here:
9+
SQLITE_AMALGAMATION = sqlite-amalgamation-3280000
10+
SQLITE_AMALGAMATION_ZIP_URL = https://www.sqlite.org/2019/sqlite-amalgamation-3280000.zip
11+
SQLITE_AMALGAMATION_ZIP_SHA1 = eb82fcc95104c8e2d9550ab023c1054b9cc40a76
12+
13+
# Note that extension-functions.c hasn't been updated since 2010-02-06, so likely doesn't need to be updated
14+
EXTENSION_FUNCTIONS = extension-functions.c
15+
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
16+
EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f
17+
818
EMCC=emcc
919

1020
CFLAGS=-O2 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DLONGDOUBLE_TYPE=double -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
@@ -117,19 +127,61 @@ out/api.js: src/output-pre.js src/api.coffee src/exports.coffee src/api-data.cof
117127
cat src/output-pre.js $@ src/output-post.js > out/api-wrapped.js
118128
mv out/api-wrapped.js $@
119129

120-
out/sqlite3.bc: sqlite/sqlite3.c
130+
out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION)
121131
# Generate llvm bitcode
122-
$(EMCC) $(CFLAGS) sqlite/sqlite3.c -o out/sqlite3.bc
132+
$(EMCC) $(CFLAGS) sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@
123133

124-
out/extension-functions.bc: sqlite/extension-functions.c
125-
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite/extension-functions.c -o out/extension-functions.bc
134+
out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
135+
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
126136

127137
# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
128138
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
129139
# tar --create --gzip $^ > $@
130140

131-
.PHONY: clean
132-
clean:
133-
rm -f out/* dist/*
141+
## cache
142+
143+
.PHONY: clean-cache
144+
clean-cache:
145+
rm -rf cache
146+
147+
cache/$(SQLITE_AMALGAMATION).zip:
148+
mkdir -p cache
149+
curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@
150+
151+
cache/$(EXTENSION_FUNCTIONS):
152+
mkdir -p cache
153+
curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@
154+
155+
## sqlite-src
156+
157+
.PHONY: clean-sqlite-src
158+
clean-sqlite-src:
159+
rm -rf sqlite
160+
161+
.PHONY: sqlite-src
162+
sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(EXTENSION_FUNCTIONS)
163+
164+
sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip
165+
mkdir -p sqlite-src
166+
echo '$(SQLITE_AMALGAMATION_ZIP_SHA1) ./cache/$(SQLITE_AMALGAMATION).zip' > cache/check.txt
167+
sha1sum -c cache/check.txt
168+
rm -rf $@
169+
unzip 'cache/$(SQLITE_AMALGAMATION).zip' -d sqlite-src/
170+
touch $@
171+
172+
sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
173+
mkdir -p sqlite-src
174+
echo '$(EXTENSION_FUNCTIONS_SHA1) ./cache/$(EXTENSION_FUNCTIONS)' > cache/check.txt
175+
sha1sum -c cache/check.txt
176+
cp 'cache/$(EXTENSION_FUNCTIONS)' $@
177+
178+
179+
.PHONY: clean
180+
clean:
181+
rm -rf out/* dist/*
134182

183+
.PHONY: clean-all
184+
clean-all:
185+
rm -f out/* dist/* cache/*
186+
rm -rf sqlite-src/
135187

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SQLite compiled to javascript
22
[![Build Status](https://travis-ci.org/kripken/sql.js.svg?branch=master)](http://travis-ci.org/kripken/sql.js) [![CDNJS version](https://img.shields.io/cdnjs/v/sql.js.svg)](https://cdnjs.com/libraries/sql.js)
33

4-
For the impatients, try the demo here: http://kripken.github.io/sql.js/GUI/
4+
For the impatients, try the demo here: http://kripken.github.io/sql.js/examples/GUI
55

66
*sql.js* is a port of [SQLite](http://sqlite.org/about.html) to Webassembly, by compiling the SQLite C code with [Emscripten](http://kripken.github.io/emscripten-site/docs/introducing_emscripten/about_emscripten.html). It uses a [virtual database file stored in memory](https://kripken.github.io/emscripten-site/docs/porting/files/file_systems_overview.html), and thus **doesn't persist the changes** made to the database. However, it allows you to **import** any existing sqlite file, and to **export** the created database as a [javascript typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).
77

@@ -11,6 +11,11 @@ SQLite is public domain, sql.js is MIT licensed.
1111

1212
Sql.js predates WebAssembly, and thus started as an [asm.js](https://en.wikipedia.org/wiki/Asm.js) project. It still supports asm.js for backwards compatability.
1313

14+
## Version of binaries
15+
Sql.js was last built with:
16+
Emscripten version 1.38.30 (2019-04-16) [Release History](https://emscripten.org/docs/introducing_emscripten/release_notes.html)
17+
SqlLite version: 3.28.0 (2019-04-16) [Release History](https://www.sqlite.org/changes.html)
18+
1419
## Documentation
1520
A [full documentation](http://kripken.github.io/sql.js/documentation/#http://kripken.github.io/sql.js/documentation/class/Database.html) generated from comments inside the source code, is available.
1621

@@ -219,7 +224,7 @@ This library includes both WebAssembly and asm.js versions of Sqlite. (WebAssemb
219224

220225
## Upgrading from 0.x to 1.x
221226

222-
Version 1.0 of sql.js introduces a number of breaking changes due primarily to the fact that WebAssembly must be loaded asynchronously, whereas asm.js was able to be loaded synchronously.
227+
Version 1.0 of sql.js must be loaded asynchronously, whereas asm.js was able to be loaded synchronously.
223228

224229
So in the past, you would:
225230
```html
@@ -255,9 +260,7 @@ initSqlJs().then(function(SQL){
255260
});
256261
```
257262

258-
259-
260-
263+
`NOTHING` is now a reserved word in SQLite, whereas previously it was not. This could cause errors like `Error: near "nothing": syntax error`
261264

262265
### Downloading/Using: ###
263266
Although asm.js files were distributed as a single Javascript file, WebAssembly libraries are most efficiently distributed as a pair of files, the `.js` loader and the `.wasm` file, like [dist/sql-wasm.js]([dist/sql-wasm.js]) and [dist/sql-wasm.wasm]([dist/sql-wasm.wasm]). The `.js` file is reponsible for wrapping/loading the `.wasm` file.

0 commit comments

Comments
 (0)