Skip to content

Commit 7f1dd3d

Browse files
committed
Merge branch 'vend'
Fixes #547
2 parents 1339eb3 + 828b72c commit 7f1dd3d

15 files changed

Lines changed: 1974 additions & 155 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ work/
5656
compile_commands.json
5757
.vscode/
5858
.cache/
59+
/apsw/sqlite_extra_binaries

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ include LICENSE
1616
include checksums
1717
include setup.py
1818

19+
# builds sqlite_extra
20+
include tools/vend.py
21+
1922
# Long description comes from this
2023
include README.rst
2124

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ help: ## Show this help
3636
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | \
3737
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
3838

39-
all: src/apswversion.h src/apsw.docstrings apsw/__init__.pyi src/constants.c src/stringconstants.c test docs checkversion ## Update generated files, build, test, make doc
39+
GENFILES = src/apswversion.h src/apsw.docstrings apsw/__init__.pyi src/constants.c src/stringconstants.c \
40+
apsw/sqlite_extra.json doc/sqlite_extra.rst-inc \
41+
$(GENDOCS) $(GENEXAMPLES)
42+
43+
all: $(GENFILES) checkversion ## Update generated files
4044

4145
tagpush: ## Tag with version and push
4246
test "`git branch --show-current`" = master
@@ -109,6 +113,12 @@ src/stringconstants.c: Makefile tools/genstrings.py src/apswversion.h
109113
-rm -f src/stringconstants.c
110114
$(PYTHON) tools/genstrings.py > src/stringconstants.c
111115

116+
apsw/sqlite_extra.json: tools/vend.py
117+
$(PYTHON) tools/vend.py json $@
118+
119+
doc/sqlite_extra.rst-inc: tools/vend.py
120+
env PYTHONPATH=. $(PYTHON) tools/vend.py rst $@
121+
112122
build_ext: src/apswversion.h apsw/__init__.pyi src/apsw.docstrings ## Fetches SQLite and builds the extension
113123
env $(PYTHON) setup.py fetch --version=$(SQLITEVERSION) --all build_ext -DSQLITE_ENABLE_COLUMN_METADATA --inplace --force --enable-all-extensions
114124
env $(PYTHON) setup.py build_test_extension
@@ -183,6 +193,7 @@ fossil: ## Grabs latest trunk from SQLite source control, extracts and builds in
183193
mkdir sqlite3
184194
set -e ; cd sqlite3 ; curl --output - $(FOSSIL_URL) | tar xfz - --strip-components=1
185195
set -e ; cd sqlite3 ; ./configure --quiet --all --column-metadata --disable-tcl $(CONFIGURE_OPTS) ; $(MAKE) sqlite3.c sqlite3 libsqlite3.so ; ln -s libsqlite3.so libsqlite3.so.0
196+
set -e ; cd sqlite3 ; curl --output - https://sqlite.org/vec1/tarball/vec1.tar.gz | tar xfz -
186197
$(PYTHON) setup.py patch
187198

188199
# the funky test stuff is to exit successfully when grep has rc==1 since that means no lines found.

apsw/shell.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import contextlib
1313
import csv
1414
import dataclasses
15+
import importlib
1516
import inspect
1617
import io
1718
import json
@@ -30,7 +31,7 @@
3031
import apsw
3132
import apsw.ext
3233
import apsw.fts5
33-
34+
import apsw.sqlite_extra
3435

3536
class Shell:
3637
"""Implements a SQLite shell
@@ -2191,7 +2192,11 @@ def command_load(self, cmd):
21912192
may need to explicitly specify the directory. For example if
21922193
it is in the current directory then use:
21932194
2194-
.load ./extension.so
2195+
.load ./extension
2196+
2197+
:doc:`sqlite_extra <extra>` will also be searched for
2198+
extensions if the parameter is not found. Use --list to see a
2199+
list available in this installation.
21952200
"""
21962201
if len(cmd) < 1 or len(cmd) > 2:
21972202
raise self.Error("load takes one or two parameters")
@@ -2200,7 +2205,23 @@ def command_load(self, cmd):
22002205
except Exception:
22012206
raise self.Error("Extension loading is not supported")
22022207

2203-
self.db.load_extension(*cmd)
2208+
try:
2209+
self.db.load_extension(*cmd)
2210+
except Exception:
2211+
if len(cmd) == 1:
2212+
if cmd[0] == "--list":
2213+
extras = json.loads(importlib.resources.files(apsw).joinpath("sqlite_extra.json").read_text())
2214+
for name, extra in sorted(extras.items()):
2215+
if extra["type"] == "extension" and apsw.sqlite_extra.has(name):
2216+
self.write_value(name, fmt = str)
2217+
self.write(self.stdout, " " * (17 - len(name)) + extra['description'] + "\n")
2218+
return
2219+
try:
2220+
apsw.sqlite_extra.load(self.db, cmd[0])
2221+
return
2222+
except (apsw.ExtensionLoadingError, LookupError, apsw.sqlite_extra.NotAvailable):
2223+
pass
2224+
raise
22042225

22052226
def log_handler(self, code, message):
22062227
"Called with SQLite log messages when logging is ON"

apsw/sqlite_extra.json

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"amatch": {
3+
"description": "Approximate matches virtual table",
4+
"type": "extension"
5+
},
6+
"anycollseq": {
7+
"description": "Fake fallback collating function for any unknown collating sequence",
8+
"type": "extension"
9+
},
10+
"appendvfs": {
11+
"description": "A VFS shim that allows an SQLite database to be appended onto the end of some other file, such as an executable",
12+
"type": "extension"
13+
},
14+
"base64": {
15+
"description": "Convert either direction between base64 blob and text",
16+
"type": "extension"
17+
},
18+
"base85": {
19+
"description": "Convert either direction between base85 blob and text",
20+
"type": "extension"
21+
},
22+
"btreeinfo": {
23+
"description": "btreeinfo virtual table that shows information about all btrees in an SQLite database file",
24+
"type": "extension"
25+
},
26+
"cksumvfs": {
27+
"description": "A VFS shim that writes a checksum on each page of an SQLite database file",
28+
"type": "extension"
29+
},
30+
"closure": {
31+
"description": "A virtual table that finds the transitive closure of a parent/child relationship in a real table",
32+
"type": "extension"
33+
},
34+
"completion": {
35+
"description": "A virtual table that returns suggested completions for a partial SQL input",
36+
"type": "extension"
37+
},
38+
"csv": {
39+
"description": "A virtual table for reading CSV files",
40+
"type": "extension"
41+
},
42+
"decimal": {
43+
"description": "Routines to implement arbitrary-precision decimal math",
44+
"type": "extension"
45+
},
46+
"eval": {
47+
"description": "Implements SQL function eval() which runs SQL statements recursively",
48+
"type": "extension"
49+
},
50+
"fileio": {
51+
"description": "Implements SQL functions readfile() and writefile(), and eponymous virtual type 'fsdir'",
52+
"type": "extension"
53+
},
54+
"fuzzer": {
55+
"description": "Virtual table that generates variations on an input word at increasing edit distances from the original",
56+
"type": "extension"
57+
},
58+
"ieee754": {
59+
"description": "functions for the exact display* and input of IEEE754 Binary64 floating-point numbers",
60+
"type": "extension"
61+
},
62+
"nextchar": {
63+
"description": "Finds all valid 'next' characters for a string given a vocabulary",
64+
"type": "extension"
65+
},
66+
"noop": {
67+
"description": "Implements noop() functions useful for testing",
68+
"type": "extension"
69+
},
70+
"prefixes": {
71+
"description": "Table valued function providing all prefixes of a string",
72+
"type": "extension"
73+
},
74+
"randomjson": {
75+
"description": "Generates random json objects",
76+
"type": "extension"
77+
},
78+
"regexp": {
79+
"description": "Compact reasonably efficient posix extended regular expression matcher",
80+
"type": "extension"
81+
},
82+
"rot13": {
83+
"description": "rot13 function and collating sequence",
84+
"type": "extension"
85+
},
86+
"sha1": {
87+
"description": "SHA1 hash and query results hash",
88+
"type": "extension"
89+
},
90+
"shathree": {
91+
"description": "SHA3 hash and query results hash",
92+
"type": "extension"
93+
},
94+
"spellfix": {
95+
"description": "Search a large vocabulary for close matches",
96+
"type": "extension"
97+
},
98+
"sqlite3_dbdump": {
99+
"description": "Converts the content of a SQLite database into UTF-8 text SQL statements that can be used to exactly recreate the original database",
100+
"type": "executable"
101+
},
102+
"sqlite3_dbhash": {
103+
"description": "Computes SHA1 of the contents of a SQLite database",
104+
"type": "executable"
105+
},
106+
"sqlite3_dbtotxt": {
107+
"description": "Converts a binary file like a database into a friendly human readable text format",
108+
"type": "executable"
109+
},
110+
"sqlite3_diff": {
111+
"description": "Displays content differences between SQLite databases",
112+
"type": "executable"
113+
},
114+
"sqlite3_expert": {
115+
"description": "A simple system to propose useful indexes given a database and a set of SQL queries",
116+
"type": "executable"
117+
},
118+
"sqlite3_getlock": {
119+
"description": "Unix only shows if and who is holding a database lock",
120+
"type": "executable"
121+
},
122+
"sqlite3_index_usage": {
123+
"description": "Given a database and a log database, shows how many times each index is used",
124+
"type": "executable"
125+
},
126+
"sqlite3_normalize": {
127+
"description": "Normalizes SQL text so private information can be removed, and to identify structurally identical queries",
128+
"type": "executable"
129+
},
130+
"sqlite3_offsets": {
131+
"description": "Shows length and offset for every TEXT or BLOB for a column of a table",
132+
"type": "executable"
133+
},
134+
"sqlite3_rsync": {
135+
"description": "Database Remote-Copy Tool",
136+
"type": "executable"
137+
},
138+
"sqlite3_scrub": {
139+
"description": "Makes a backup zeroing out all deleted content",
140+
"type": "executable"
141+
},
142+
"sqlite3_shell": {
143+
"description": "Command line shell",
144+
"type": "executable"
145+
},
146+
"sqlite3_showdb": {
147+
"description": "Prints low level details about a database file",
148+
"type": "executable"
149+
},
150+
"sqlite3_showjournal": {
151+
"description": "Prints low level content of a journal",
152+
"type": "executable"
153+
},
154+
"sqlite3_showlocks": {
155+
"description": "Shows all posix advisory locks on a file",
156+
"type": "executable"
157+
},
158+
"sqlite3_showshm": {
159+
"description": "Shows low level content of shm and wal-index files",
160+
"type": "executable"
161+
},
162+
"sqlite3_showstat4": {
163+
"description": "Shows contents of stat4 index of a database",
164+
"type": "executable"
165+
},
166+
"sqlite3_showtmlog": {
167+
"description": "Makes human/csv readable output from a tmstmpvfs log file",
168+
"type": "executable"
169+
},
170+
"sqlite3_showwal": {
171+
"description": "Shows low level content of a WAL file",
172+
"type": "executable"
173+
},
174+
"stmt": {
175+
"description": "Virtual table with information about all prepared statements on a connection",
176+
"type": "extension"
177+
},
178+
"stmtrand": {
179+
"description": "Function that returns the same sequence of random integers is returned for each invocation of the statement",
180+
"type": "extension"
181+
},
182+
"tmstmpvfs": {
183+
"description": "VFS shim that writes timestamps and other tracing information to the reserved bytes of each page, and also generates corresponding log files",
184+
"type": "extension"
185+
},
186+
"uint": {
187+
"description": "UINT collating sequence",
188+
"type": "extension"
189+
},
190+
"unionvtab": {
191+
"description": "Virtual table combining underlying tables from other databases",
192+
"type": "extension"
193+
},
194+
"uuid": {
195+
"description": "uuid functions",
196+
"type": "extension"
197+
},
198+
"vec1": {
199+
"description": "Vector search. !Experimental! !Under development! Loading on before 2013 CPU may crash process",
200+
"type": "extension"
201+
},
202+
"vfsstat": {
203+
"description": "VFS shim tracking call statistics",
204+
"type": "extension"
205+
},
206+
"vtablog": {
207+
"description": "Virtual table printing diagnostic information for interactive analysis and debugging",
208+
"type": "extension"
209+
},
210+
"zorder": {
211+
"description": "Functions for z-order (Morton code) transformations",
212+
"type": "extension"
213+
}
214+
}

0 commit comments

Comments
 (0)