Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed problem in which SpatiaLite library would not be loaded for the…

… connection under certain circumstances, e.g., when using the geographic admin. Thanks, jtiai, for the bug report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12037 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f2d0ae93f859e31d9591f4b4b35890b320e9129c 1 parent dae4972
@jbronn jbronn authored
View
29 django/contrib/gis/db/backends/spatialite/base.py
@@ -9,7 +9,6 @@
from django.contrib.gis.db.backends.spatialite.creation import SpatiaLiteCreation
from django.contrib.gis.db.backends.spatialite.operations import SpatiaLiteOperations
-
class DatabaseWrapper(SqliteDatabaseWrapper):
def __init__(self, *args, **kwargs):
# Before we get too far, make sure pysqlite 2.5+ is installed.
@@ -36,6 +35,7 @@ def __init__(self, *args, **kwargs):
def _cursor(self):
if self.connection is None:
+ ## The following is the same as in django.db.backends.sqlite3.base ##
settings_dict = self.settings_dict
if not settings_dict['NAME']:
from django.core.exceptions import ImproperlyConfigured
@@ -50,7 +50,11 @@ def _cursor(self):
self.connection.create_function("django_extract", 2, _sqlite_extract)
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
self.connection.create_function("regexp", 2, _sqlite_regexp)
+ connection_created.send(sender=self.__class__)
+
+ ## From here on, customized for GeoDjango ##
+ # Enabling extension loading on the SQLite connection.
try:
self.connection.enable_load_extension(True)
except AttributeError:
@@ -59,15 +63,14 @@ def _cursor(self):
'the loading of extensions to use SpatiaLite.'
)
- connection_created.send(sender=self.__class__)
- return self.connection.cursor(factory=SQLiteCursorWrapper)
-
- def load_spatialite(self):
- """
- Loads the SpatiaLite library.
- """
- try:
- self._cursor().execute("SELECT load_extension(%s)", (self.spatialite_lib,))
- except Exception, msg:
- raise ImproperlyConfigured('Unable to load the SpatiaLite extension '
- '"%s" because: %s' % (self.spatialite_lib, msg))
+ # Loading the SpatiaLite library extension on the connection, and returning
+ # the created cursor.
+ cur = self.connection.cursor(factory=SQLiteCursorWrapper)
+ try:
+ cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
+ except Exception, msg:
+ raise ImproperlyConfigured('Unable to load the SpatiaLite library extension '
+ '"%s" because: %s' % (self.spatialite_lib, msg))
+ return cur
+ else:
+ return self.connection.cursor(factory=SQLiteCursorWrapper)
View
3  django/contrib/gis/db/backends/spatialite/creation.py
@@ -24,8 +24,7 @@ def create_test_db(self, verbosity=1, autoclobber=False):
self.connection.settings_dict["NAME"] = test_database_name
can_rollback = self._rollback_works()
self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
- # Need to load the SpatiaLite library and initializatin SQL before running `syncdb`.
- self.connection.load_spatialite()
+ # Need to load the SpatiaLite initialization SQL before running `syncdb`.
self.load_spatialite_sql()
call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
View
10 django/contrib/gis/db/backends/spatialite/operations.py
@@ -51,8 +51,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
name = 'spatialite'
spatialite = True
version_regex = re.compile(r'^(?P<major>\d)\.(?P<minor1>\d)\.(?P<minor2>\d+)')
- valid_aggregates = dict([(k, None) for k in
- ('Extent', 'Union')])
+ valid_aggregates = dict([(k, None) for k in ('Extent', 'Union')])
Adapter = SpatiaLiteAdapter
@@ -112,10 +111,7 @@ def __init__(self, connection):
super(DatabaseOperations, self).__init__()
self.connection = connection
- # Load the spatialite library (must be done before getting the
- # SpatiaLite version).
- self.connection.load_spatialite()
-
+ # Determine the version of the SpatiaLite library.
try:
vtup = self.spatialite_version_tuple()
version = vtup[1:]
@@ -269,7 +265,7 @@ def spatial_lookup_sql(self, lvalue, lookup_type, value, field, qn):
"""
Returns the SpatiaLite-specific SQL for the given lookup value
[a tuple of (alias, column, db_type)], lookup type, lookup
- value, and the model field.
+ value, the model field, and the quoting function.
"""
alias, col, db_type = lvalue
Please sign in to comment.
Something went wrong with that request. Please try again.