From f36e5d68d928b9ed8d9702ec58da54deb2d9896e Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Tue, 12 Sep 2017 08:27:29 +0500 Subject: [PATCH] Used sqlite3.Connection.load_extension() instead of query execution for SpatiaLite loading. --- django/contrib/gis/db/backends/spatialite/base.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/django/contrib/gis/db/backends/spatialite/base.py b/django/contrib/gis/db/backends/spatialite/base.py index 2b2a342b114..7aea4f21ede 100644 --- a/django/contrib/gis/db/backends/spatialite/base.py +++ b/django/contrib/gis/db/backends/spatialite/base.py @@ -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):