Skip to content

Commit 5b23d0f

Browse files
committed
Update recommended compile options
Fixes #596
1 parent c74b6d9 commit 5b23d0f

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

apsw/tests/__main__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12104,11 +12104,7 @@ def setup():
1210412104
try:
1210512105
apsw.config(apsw.SQLITE_CONFIG_MEMSTATUS, True) # ensure memory tracking is on
1210612106
except apsw.MisuseError:
12107-
# if using amalgamation then something went wrong
12108-
if apsw.using_amalgamation:
12109-
raise
12110-
# coverage uses sqlite and so the config call is too
12111-
# late
12107+
# sqlite was already initialized
1211212108
pass
1211312109
apsw.initialize() # manual call for coverage
1211412110
memdb = apsw.Connection(":memory:")

doc/changes.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ APSW changes by version
1414
========
1515

1616
Comprehensive async support - connections run in a dedicated worker
17-
with the event loop able to :code:`await` the results.
17+
thread with the event loop able to :code:`await` the results.
1818

1919
* :mod:`asyncio`, |trio|, and |anyio| are supported and tested
2020
* Async callbacks can be used anywhere including:
@@ -60,6 +60,28 @@ and right align integers. That updates the :doc:`shell <shell>` output.
6060
Update :func:`fork_checker` and :func:`shutdown` for more robustness
6161
(:issue:`602`)
6262

63+
Amalgamation builds **only** (eg PyPI): Following the `recommended
64+
compile time options
65+
<https://sqlite.org/compile.html#recommended_compile_time_options>`__,
66+
the following options are now set. Other applicable recommendations
67+
were done in earlier releases. You can use
68+
:attr:`apsw.compile_options` to see what is in effect.
69+
70+
* `SQLITE_OMIT_AUTOINIT
71+
<https://sqlite.org/compile.html#omit_autoinit>`__.
72+
:func:`initialize` is called when APSW is loaded. **Backwards
73+
incompatible change:** This will only affect :func:`apsw.config` calls
74+
made before anything else, and will now require an explicit :func:`apsw.shutdown`,
75+
:func:`apsw.config`, and :func:`apsw.initialize`.
76+
77+
* `SQLITE_STRICT_SUBTYPE <https://sqlite.org/compile.html#strict_subtype>`__ -
78+
subtypes are not exposed in APSW, but are used by SQLite builtin functions.
79+
80+
* `SQLITE_LIKE_DOESNT_MATCH_BLOBS
81+
<https://sqlite.org/compile.html#like_doesnt_match_blobs>`__ which
82+
is a **backwards incompatible change** if you deliberately use
83+
:code:`LIKE` against blobs, which is not a good idea.
84+
6385
Take advantage of :code:`SQLITE_UTF8_ZT` encoding and
6486
`sqlite3_carray_bind_v2
6587
<https://sqlite.org/draft/c3ref/carray_bind.html>`__ in the C code.

src/apsw.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ API Reference
8686
#define SQLITE_ENABLE_SETLK_TIMEOUT 1
8787
#endif
8888

89+
#ifndef SQLITE_OMIT_AUTOINIT
90+
#define SQLITE_OMIT_AUTOINIT 1
91+
#endif
92+
93+
#ifndef SQLITE_STRICT_SUBTYPE
94+
#define SQLITE_STRICT_SUBTYPE 1
95+
#endif
96+
97+
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
98+
#define SQLITE_LIKE_DOESNT_MATCH_BLOBS 1
99+
#endif
100+
89101
#ifndef SQLITE_DEBUG
90102
#define SQLITE_API static
91103
#define SQLITE_EXTERN static
@@ -2012,6 +2024,18 @@ PyInit_apsw(void)
20122024
PyErr_Format(PyExc_EnvironmentError, "SQLite was compiled without thread safety and cannot be used.");
20132025
goto fail;
20142026
}
2027+
2028+
#ifdef APSW_USE_SQLITE_AMALGAMATION
2029+
{
2030+
int rc = sqlite3_initialize();
2031+
if (rc != SQLITE_OK)
2032+
{
2033+
PyErr_Format(PyExc_RuntimeError, "SQLite failed to initialize with code %d", rc);
2034+
goto fail;
2035+
}
2036+
}
2037+
#endif
2038+
20152039
module_is_initialized = 0;
20162040
if (ApswModuleType.tp_base == NULL)
20172041
{

0 commit comments

Comments
 (0)