Browse Source

Fix libspatialite.so: undefined symbol: sqlite3_spatialite_init

Spatialite module name has changed in Debian stretch.
This commit implements auto-detection on first connection to sqlite DB.
pitchum 7 years ago
parent
commit
ab57756b95
2 changed files with 16 additions and 1 deletions
  1. 4 0
      README.md
  2. 12 1
      ffdnispdb/__init__.py

+ 4 - 0
README.md

@@ -18,6 +18,10 @@ On a Debian Jessie system, do:
 
     apt install sqlite3 libspatialite-dev build-essential python-dev
 
+On a Debian Stretch system, do:
+
+    apt install sqlite3 libsqlite3-mod-spatialite build-essential python-dev
+
 Preferably in a virtualenv, run:
 
     pip install -r requirements.txt

+ 12 - 1
ffdnispdb/__init__.py

@@ -34,10 +34,21 @@ def create_app(config={}):
     db.init_app(app)
 
     with app.app_context():
+        @event.listens_for(db.engine, "first_connect")
+        def connect(sqlite, connection_rec):
+            sqlite.enable_load_extension(True)
+            try:
+                sqlite.execute('select load_extension("libspatialite")')
+                current_app.spatialite_modulename = 'libspatialite'
+            except Exception as e:
+                sqlite.execute('select load_extension("mod_spatialite")')
+                current_app.spatialite_modulename = 'mod_spatialite'
+            sqlite.enable_load_extension(False)
+
         @event.listens_for(db.engine, "connect")
         def connect(sqlite, connection_rec):
             sqlite.enable_load_extension(True)
-            sqlite.execute('select load_extension("libspatialite.so")')
+            sqlite.execute('select load_extension("%s")' % current_app.spatialite_modulename)
             sqlite.enable_load_extension(False)
 
     app.session_interface = sess