From ba3e807a274ee56ea94c18f2f313bab82affd6db Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Fri, 18 Nov 2022 11:39:11 -0800 Subject: [PATCH] Explicit test of presence of SQLite math functions We cannot count on version numbers to determine if SQLite has math functions because the sqlite3 library may or may not have been compiled with the DSQLITE_ENABLE_MATH_FUNCTIONS option. This commit explicitly tests for the presence of math functions. --- bin/weedb/sqlite.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/weedb/sqlite.py b/bin/weedb/sqlite.py index 07336b9f..08adcedc 100644 --- a/bin/weedb/sqlite.py +++ b/bin/weedb/sqlite.py @@ -16,8 +16,16 @@ if not hasattr(sqlite3.Connection, "__exit__"): # @UndefinedVariable del sqlite3 from pysqlite2 import dbapi2 as sqlite3 # @Reimport @UnresolvedImport -sqlite_version = sqlite3.sqlite_version -has_math = sqlite_version >= '3.35.0' +# Test to see whether this version of SQLite has math functions. An explicit test is required +# (rather than just check version numbers) because the SQLite library may or may not have been +# compiled with the DSQLITE_ENABLE_MATH_FUNCTIONS option. +try: + with sqlite3.connect(":memory:") as conn: + conn.execute("SELECT RADIANS(0.0), SIN(0.0), COS(0.0);") +except sqlite3.OperationalError: + has_math = False +else: + has_math = True import weedb from weeutil.weeutil import to_int, to_bool