Used sqlite3.Connection.load_extension() instead of query execution for SpatiaLite loading.

This commit is contained in:
Sergey Fedoseev 2017-09-12 08:27:29 +05:00 committed by Tim Graham
parent 0dbcd0e87f
commit f36e5d68d9
1 changed files with 3 additions and 6 deletions

View File

@ -3,7 +3,7 @@ from ctypes.util import find_library
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.sqlite3.base import (
DatabaseWrapper as SQLiteDatabaseWrapper, SQLiteCursorWrapper,
DatabaseWrapper as SQLiteDatabaseWrapper,
)
from .client import SpatiaLiteClient
@ -46,16 +46,13 @@ class DatabaseWrapper(SQLiteDatabaseWrapper):
'SpatiaLite requires SQLite to be configured to allow '
'extension loading.'
)
# Loading the SpatiaLite library extension on the connection, and returning
# the created cursor.
cur = conn.cursor(factory=SQLiteCursorWrapper)
# Load the SpatiaLite library extension on the connection.
try:
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
conn.load_extension(self.spatialite_lib)
except Exception as exc:
raise ImproperlyConfigured(
'Unable to load the SpatiaLite library extension "%s"' % self.spatialite_lib
) from exc
cur.close()
return conn
def prepare_database(self):