Commit ab57756b authored by pitchum's avatar pitchum

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.
parent 1a4d8553
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment