How to use the new SQLite STRICT keyword with Python 3?

SQLite 3.37 added support for strict type checking via the new STRICT
keyword.
However, the SQLite3 module bundled with Python 3.7.9 cannot work with it (sqlite3.DatabaseError: malformed database schema (tableName) - near “STRICT”: syntax error).

Can you show a small piece of code demonstrating this error please?

What can I do about this? Do I need to build Python with the latest SQLite myself?

Maybe.

Here’s a Mac homebrew Python 3.9.9:

Python 3.9.9 (main, Nov 21 2021, 03:22:47)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import sqlite3
>>> sqlite3.version
'2.6.0'
>>> sqlite3.sqlite_version
'3.37.0'
>>>

which suggests it has been built against sqlite3 3.37.0. Which may
simply the be sqlite3 available when homebrew built it here on my
machine (or when a homebrew binary install image was built).

What does your Python report for the above?

Also, which (future) Python version will start supporting this new
feature?

When the 3.37 come out? And Python 3.7.9? It may be as simple as 3.37
not being available when the Python 3.7.9 prebuilt bundle was
constructed for the download page.

So it may not be “Python supporting this keyword” but “SQLite3 3.37
being present at build time”. Try building Python yourself with that
revision of SQLite present, or fetching a newer Python.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like