Hi,
got an issue with spatialite in qgis, where python code would try to
load the spatialite extension into an sqlite database - thing is, this
seems disabled by default, and the following code blows:
$cat t.py
import sqlite3
con = sqlite3.connect(":memory:")
con.enable_load_extension(True)
$python3 t.py
Traceback (most recent call last):
File "t.py", line 6, in <module>
con.enable_load_extension(True)
AttributeError: 'sqlite3.Connection' object has no attribute
'enable_load_extension'
Apparently this is a known problem on both sqlite and python sides, per
https://riccardo.forina.me/spatialite-for-python-does-not-work-on-osx/
and
https://docs.python.org/3.6/library/sqlite3.html#sqlite3.Connection.enable_load_extension,
the latter which says in the footnote:
'The sqlite3 module is not built with loadable extension support by
default, because some platforms (notably Mac OS X) have SQLite libraries
which are compiled without this feature. To get loadable extension
support, you must pass –enable-loadable-sqlite-extensions to configure.'
Macports apparently builds python itself with this flag, per
https://trac.macports.org/ticket/49317
Our sqlite has --enable-dynamic-extensions implicitely as the default
value is yes, but python itself wont work with its default options.
The problem doesnt seem to exist on FreeBSD, but it seems they dont
explicitely pass -–enable-loadable-sqlite-extensions. I dont understand
why, maybe because they disable the sqlite3 extension in their python3
build and build it as a separate port, cf
https://svnweb.freebsd.org/ports/head/lang/python36/Makefile?view=markup#l30
& https://svnweb.freebsd.org/ports/head/databases/py-sqlite3/Makefile .
Anyway, with the attached python3 diff, the 3-line testcase works, and i
can use spatialite databases in qgis3. I'm not sure this is worth a
bulk, but i can dust off my vm cluster if needed.
Feedback & comments welcome.
Landry
Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/python/3.6/Makefile,v
retrieving revision 1.11
diff -u -r1.11 Makefile
--- Makefile 2 Jul 2018 04:56:07 -0000 1.11
+++ Makefile 22 Aug 2018 07:33:31 -0000
@@ -9,8 +9,10 @@
PATCHLEVEL = .6
SHARED_LIBS = python3.6m 0.0
VERSION_SPEC = >=3.6,<3.7
+REVISION = 0
CONFIGURE_ARGS += --with-ensurepip=no
+CONFIGURE_ARGS += --enable-loadable-sqlite-extensions
CONFIGURE_STYLE = autoconf