db.sqlite_version property and fix for deterministic=True on SQLite 3.8.3

Closes #408
This commit is contained in:
Simon Willison 2022-03-01 16:24:27 -08:00
commit d25cdd37a3
4 changed files with 47 additions and 3 deletions

View file

@ -387,7 +387,11 @@ class Database:
if not replace and (name, arity) in self._registered_functions:
return fn
kwargs = {}
if deterministic and sys.version_info >= (3, 8):
if (
deterministic
and sys.version_info >= (3, 8)
and self.sqlite_version >= (3, 8, 3)
):
kwargs["deterministic"] = True
self.conn.create_function(name, arity, fn, **kwargs)
self._registered_functions.add((name, arity))
@ -547,6 +551,12 @@ class Database:
except Exception:
return False
@property
def sqlite_version(self) -> Tuple[int, ...]:
"Version of SQLite, as a tuple of integers e.g. (3, 36, 0)"
row = self.execute("select sqlite_version()").fetchall()[0]
return tuple(map(int, row[0].split(".")))
@property
def journal_mode(self) -> str:
"Current ``journal_mode`` of this database."