Skip to content

Commit d238a36

Browse files
committed
Inckude zlib related extra
1 parent 454e002 commit d238a36

9 files changed

Lines changed: 153 additions & 36 deletions

File tree

apsw/sqlite_extra.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"description": "A virtual table that returns suggested completions for a partial SQL input",
3636
"type": "extension"
3737
},
38+
"compress": {
39+
"description": "SQL compression functions",
40+
"type": "extension"
41+
},
3842
"csv": {
3943
"description": "A virtual table for reading CSV files",
4044
"type": "extension"
@@ -99,6 +103,10 @@
99103
"description": "Search a large vocabulary for close matches",
100104
"type": "extension"
101105
},
106+
"sqlar": {
107+
"description": "Command line SQL archive tool",
108+
"type": "executable"
109+
},
102110
"sqlite3_dbdump": {
103111
"description": "Converts the content of a SQLite database into UTF-8 text SQL statements that can be used to exactly recreate the original database",
104112
"type": "executable"
@@ -211,6 +219,10 @@
211219
"description": "Virtual table printing diagnostic information for interactive analysis and debugging",
212220
"type": "extension"
213221
},
222+
"zipfile": {
223+
"description": "Read/Write access to simple archives",
224+
"type": "extension"
225+
},
214226
"zorder": {
215227
"description": "Functions for z-order (Morton code) transformations",
216228
"type": "extension"

apsw/tests/extratest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def testExecutable(self):
8585
print(f" >> Executable {name}")
8686
cmd = apsw.sqlite_extra.path(name)
8787
match name:
88+
case "sqlar":
89+
self.run_cmd([cmd, pathlib.Path(tmpd) / f"{spicy}.sqlar", dbf])
90+
8891
case "sqlite3_dbdump" | "sqlite3_dbhash" | "sqlite3_dbtotxt":
8992
self.run_cmd([cmd, dbf], spicy)
9093

checksums

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# This file contains checksums/hashes of SQLite so that we can verify
1+
# This file contains checksums/hashes of SQLite downloads so that we can verify
22
# downloads using fetch command to setup.py have not been
33
# tampered with. See https://rogerbinns.github.io/apsw/install.html#fetch
44
# for information on setup.py flags.
55

66
# Format is URL length sha256 sha3_256 all on one line.
77
# This extra checking mechanism is to give you a little bit
8-
# more peace of mind because the SQLite releases are not signed in any
8+
# more peace of mind because the releases are not signed in any
99
# way.
1010

11+
# These are used too compile sqlite extra
12+
1113
https://sqlite.org/vec1/zip/vec1-20260306155250-d070184523.zip 75980 6a58eebbe1e4679645c80084fdfc44f2902e19cde95da5af932bb51bfdc7d02d 77785c8f4e0a9672dded6794861a2ca9d5a5a8dda43300b183690cd84149bf35
14+
https://sqlite.org/sqlar/zip/sqlar-src-20180107193712-4824e73896.zip 1980460 63bc4b3459fd00498f161d87d8b4516a581278da900001af183486458396806c c7b6a21b58e7499b7c3e36f26b7fafe44ddbd85097b37d905d72ccf5ff3e7cb8
15+
https://www.zlib.net/zlib132.zip 1616754 e8bf55f3017aa181690990cb58a994e77885da140609fc8f94abe9b65d2cae28 6b35b981f73425dc5f142cbee457f078d42240c022c804982849b962f1d1e2c6
16+
17+
# SQLite releases
18+
1219
https://sqlite.org/2026/sqlite-autoconf-3520000.tar.gz 3258980 f6b50b0c103392af32a8be15b2b9d25959de9a00a70c3979128aafeaa5338b3f 45a4911475950ab5fd486afb776102eb29d69e7569b48947f21e3c8501b51822
1320
https://sqlite.org/2026/sqlite-src-3520000.zip 14346407 652a98ca833ed638809a52bec225a7f37799f71a995778f9ccb68ad03bd1fc11 a2f0a14b6530138b0c8c096f4b5e5c9d3c1b8a5effa565c91f983e1235f9e26a
1421

doc/changes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ history <https://devguide.python.org/versions/>`__.
1010
APSW changes by version
1111
-----------------------
1212

13+
3.51.3.0
14+
========
15+
16+
Includes all the changes from the 3.52.0.0 release listed below,
17+
except :code:`SQLITE_UTF8_ZT` and :code:`sqlite3_carray_bind_v2`.
18+
19+
:doc:`extra` adds extensions and programs that require the `zlib
20+
compression library <https://www.zlib.net/>`__, notably `zipfile
21+
<https://sqlite.org/zipfile.html>`__ and `sqlar
22+
<https://sqlite.org/sqlar.html>`__
23+
1324
3.52.0.0
1425
========
1526

doc/extra.rst

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ documentation as the main library.
88

99
Full APSW builds such as those on PyPI include all the ones that
1010
compile for that platform, without any modifications. This is for
11-
convenience and to help promote these great extras. They add just
11+
convenience, and to help promote these great extras. They add just
1212
over 1MB to the download and 3MB of disk space.
1313

1414
Access is provided via an :ref:`API <extra_api>`, :ref:`command line
@@ -27,17 +27,30 @@ the SQLite team. It is also included with the extras if possible.
2727
Dependencies
2828
------------
2929

30-
There are no dependencies for the extensions and programs. That means
31-
they can be used on other compatible systems. Some of the programs
32-
require the SQLite library alongside the program which **must** be
33-
placed in the same directory as the program if you copy the program
34-
elsewhere. (The SQLite library in that directory deliberately has a
35-
different name to avoid interactions with the standard system SQLite
36-
library.)
37-
38-
Extensions and programs that require third party libraries (eg
39-
compression), or TCL are not included, and optional third party
40-
libraries (eg readline) are not used.
30+
There are no dependencies for the extensions or tools.
31+
32+
zlib
33+
++++
34+
35+
Some of the extensions and programs use the `zlib compression library
36+
<https://www.zlib.net/>`__ (`license
37+
<https://www.zlib.net/zlib_license.html>`__) which is included
38+
statically for those extensions and programs.
39+
40+
TCL
41+
+++
42+
43+
Some of the tools require `TCL <https://www.tcl-lang.org/>`__ and are
44+
omitted.
45+
46+
Readline
47+
++++++++
48+
49+
The shell can optionally use the readline (or editline) library for
50+
editing at the shell prompt. This is disabled to avoid the
51+
dependency. You can use the APSW :doc:`shell`, or the extra provided
52+
one with `rlwrap <https://linux.die.net/man/1/rlwrap>`__ if you need
53+
significant editing functionality.
4154

4255
Marking
4356
-------

doc/sqlite_extra.rst-inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Programs
55
--------
66

77

8+
sqlar (`doc <https://sqlite.org/sqlar/>`__)
9+
10+
Command line SQL archive tool
11+
812
sqlite3_dbdump (`doc <https://sqlite.org/src/file?ci=trunk&name=ext%2fmisc%2fdbdump.c>`__)
913

1014
Converts the content of a SQLite database into UTF-8 text SQL statements that can be used to exactly recreate the original database
@@ -148,6 +152,12 @@ Extensions
148152
-
149153
* VTable: :code:`completion`
150154

155+
* - compress
156+
- `link <https://sqlite.org/src/file?ci=trunk&name=ext%2fmisc%2fcompress.c>`__
157+
- SQL compression functions
158+
-
159+
* Function: :code:`compress` :code:`uncompress`
160+
151161
* - csv
152162
- `link <https://sqlite.org/csv.html>`__
153163
- A virtual table for reading CSV files
@@ -305,6 +315,13 @@ Extensions
305315
-
306316
* VTable: :code:`vtablog`
307317

318+
* - zipfile
319+
- `link <https://sqlite.org/zipfile.html>`__
320+
- Read/Write access to simple archives
321+
-
322+
* Function: :code:`zipfile` :code:`zipfile_cds`
323+
* VTable: :code:`zipfile`
324+
308325
* - zorder
309326
- `link <https://sqlite.org/src/file?ci=trunk&name=ext%2fmisc%2fzorder.c>`__
310327
- Functions for z-order (Morton code) transformations

setup.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,32 @@ def run(self):
298298
modtime = datetime.datetime(*zi.date_time).timestamp()
299299
self.extract_entry(zipf.read(zi), zi.filename, modtime)
300300

301-
write(" Getting the experiment vec1 extension")
302-
303-
AURL = "https://sqlite.org/vec1/zip/vec1-20260306155250-d070184523.zip"
304-
305-
data = self.download(AURL, checksum=True)
306-
307-
with zipfile.ZipFile(data) as zipf:
308-
for zi in zipf.infolist():
309-
if zi.is_dir():
310-
continue
311-
modtime = datetime.datetime(*zi.date_time).timestamp()
312-
self.extract_entry(zipf.read(zi), zi.filename, modtime, replace="sqlite3/vec1")
301+
for desc, url, replace in (
302+
(
303+
"experimental vec1 extension source",
304+
"https://sqlite.org/vec1/zip/vec1-20260306155250-d070184523.zip",
305+
"sqlite3/vec1",
306+
),
307+
(
308+
"sqlar tool source",
309+
"https://sqlite.org/sqlar/zip/sqlar-src-20180107193712-4824e73896.zip",
310+
"sqlite3/sqlar",
311+
),
312+
(
313+
"zlib source",
314+
"https://www.zlib.net/zlib132.zip",
315+
"sqlite3/zlib",
316+
),
317+
):
318+
write(f" Getting the {desc}")
319+
data = self.download(url, checksum=True)
320+
321+
with zipfile.ZipFile(data) as zipf:
322+
for zi in zipf.infolist():
323+
if zi.is_dir():
324+
continue
325+
modtime = datetime.datetime(*zi.date_time).timestamp()
326+
self.extract_entry(zipf.read(zi), zi.filename, modtime, replace=replace)
313327

314328
## The amalgamation is a .tar.gz
315329
if self.sqlite:

tools/checksums.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"3510000",
1818
)
1919

20-
vec1_urls = ("https://sqlite.org/vec1/zip/vec1-20260306155250-d070184523.zip",)
20+
other_urls = ("https://sqlite.org/vec1/zip/vec1-20260306155250-d070184523.zip",
21+
"https://sqlite.org/sqlar/zip/sqlar-src-20180107193712-4824e73896.zip",
22+
"https://www.zlib.net/zlib132.zip",)
2123

2224
fixup_download_url = setup.fixup_download_url
2325

@@ -47,13 +49,13 @@ def check(url, data):
4749
else:
4850
print(url, d[0], d[1], d[2])
4951

50-
for vec1 in vec1_urls:
52+
for url in other_urls:
5153
try:
52-
data = urllib.request.urlopen(vec1).read()
54+
data = urllib.request.urlopen(url).read()
5355
except:
54-
print(vec1)
56+
print(url)
5557
raise
56-
check(vec1, data)
58+
check(url, data)
5759

5860
for v in sqlitevers:
5961
# All platforms amalgamation

tools/vend.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Extra:
3232
"true if needing to link against sqlite3.c"
3333
lib_sqlite_stdio: bool = False
3434
"true if needing sqlite3_stdio"
35+
lib_zlib: bool = False
36+
"true if needing zlib - we statically link in"
3537
sources: list[str] = dataclasses.field(default_factory=list[str])
3638
"list of files making source for this extra relative to sqlite3 directory"
3739
type: Literal["extension"] | Literal["executable"] = "extension"
@@ -91,6 +93,11 @@ def __post_init__(self):
9193
description="A virtual table that returns suggested completions for a partial SQL input",
9294
doc="completion.html",
9395
),
96+
Extra(
97+
name="compress",
98+
description="SQL compression functions",
99+
lib_zlib=True,
100+
),
94101
Extra(
95102
name="csv",
96103
description="A virtual table for reading CSV files",
@@ -199,6 +206,11 @@ def __post_init__(self):
199206
),
200207
# vtshim: not useful
201208
# wholenumber: use generate_series
209+
Extra(
210+
name="zipfile",
211+
doc="zipfile.html",
212+
description="Read/Write access to simple archives",
213+
),
202214
# zipfile: requires libz
203215
Extra(
204216
name="zorder",
@@ -302,7 +314,7 @@ def __post_init__(self):
302314
lib_sqlite=True,
303315
# work around sqlite's mistaken handling of utf8 on windows. it should be
304316
# using manifest but instead only has a hacky main thing going on
305-
defines = [("main", "main")]
317+
defines=[("main", "main")],
306318
),
307319
Extra(
308320
name="sqlite3_showdb",
@@ -348,6 +360,14 @@ def __post_init__(self):
348360
sources=["tool/showwal.c"],
349361
description="Shows low level content of a WAL file",
350362
),
363+
Extra(
364+
name="sqlar",
365+
type="executable",
366+
sources=["sqlar/sqlar.c"],
367+
doc="sqlar/",
368+
description="Command line SQL archive tool",
369+
lib_sqlite=True,
370+
),
351371
]
352372

353373
import os
@@ -436,7 +456,7 @@ def make_windows_resource(manifest_filename: str | None, **fields):
436456
"""
437457

438458

439-
def resource_file(build_dir, compiler, extra: Extra):
459+
def resource_file(build_dir, compiler, extra: Extra) -> str:
440460
if compiler.compiler_type == "msvc":
441461
if extra.type == "executable":
442462
with open(build_dir / "utf8_manifest", "wt") as mf:
@@ -493,18 +513,21 @@ def exc_type(exc: Exception) -> str:
493513
raise
494514
return type(exc).__name__
495515

516+
496517
@dataclasses.dataclass
497518
class CompilerImplementation:
498519
"""What is the actual compiler
499520
500521
Sometimes call we know is it is cc so the implementation
501522
details are determined by compile_check"""
523+
502524
name: Literal["gcc"] | Literal["clang"] | Literal["msvc"] | Literal["unknown"]
503525
version: str
504526
"random text"
505527
misc: set[str]
506528
"the various other things"
507529

530+
508531
def do_build(what: set[str], verbose: bool, fail_fast: bool = False):
509532
get_version()
510533
compiler = ccompiler.new_compiler(verbose=True)
@@ -539,7 +562,7 @@ def do_build(what: set[str], verbose: bool, fail_fast: bool = False):
539562
objs = compiler.compile([compile_check_name], output_dir=str(build_dir))
540563
compiler.link_executable(objs, "compile_check", output_dir=str(build_dir))
541564
out_name = f"{build_dir}/compile_check{compiler.exe_extension if compiler.exe_extension else ''}"
542-
p =subprocess.run([out_name], capture_output=True, encoding="utf8", text=True)
565+
p = subprocess.run([out_name], capture_output=True, encoding="utf8", text=True)
543566
p.check_returncode()
544567
info = p.stdout.splitlines()
545568
ci = CompilerImplementation(info[0], info[1], set(info[2:]))
@@ -609,18 +632,33 @@ def do_build(what: set[str], verbose: bool, fail_fast: bool = False):
609632
lib_enables = "CARRAY COLUMN_METADATA DBPAGE_VTAB DBSTAT_VTAB FTS4 FTS5 GEOPOLY MATH_FUNCTIONS PERCENTILE PREUPDATE_HOOK RTREE SESSION STAT4".split()
610633

611634
macros = [(f"SQLITE_ENABLE_{enable}", 1) for enable in lib_enables]
635+
636+
# add in others
637+
macros.extend(
638+
[
639+
("SQLITE_CONFIG_URI", 1),
640+
("SQLITE_THREADSAFE", 1),
641+
]
642+
)
643+
612644
cfg = pathlib.Path("sqlite3") / "sqlite_cfg.h"
613645
if cfg.exists():
614646
macros.append(("_HAVE_SQLITE_CONFIG_H", 1))
615-
macros.append(("SQLITE_THREADSAFE", 1))
647+
648+
# we need a subset of zlib source files
649+
zlib_sources = [
650+
str(pathlib.Path("sqlite3/zlib") / f"{name}.c")
651+
for name in "adler32 crc32 deflate inflate inffast inftrees zutil trees compress uncompr".split()
652+
]
653+
616654
if compiler.compiler_type == "msvc":
617655
macros.append(("SQLITE_API", "__declspec(dllexport)"))
618656
try:
619657
lib_resource = resource_file(
620658
build_dir, compiler, Extra(name="libsqlite3", description="SQLite 3 library", doc="")
621659
)
622660
lib_objs = compiler.compile(
623-
[str(pathlib.Path("sqlite3") / "sqlite3.c"), lib_resource],
661+
[str(pathlib.Path("sqlite3") / "sqlite3.c"), lib_resource] + zlib_sources,
624662
output_dir=str(build_dir),
625663
macros=macros,
626664
extra_preargs=compile_extra_preargs,

0 commit comments

Comments
 (0)