diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2012-11-27 18:33:56 +0200 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-11-27 19:47:22 +0200 |
| commit | 86644e065fbde410aa32e052e206d1c53a916fd3 (patch) | |
| tree | f61b0addcc53f69a63778aaf605181d1e926b1e8 | |
| parent | 64f6e0370a8d8d2c088f189b622fa4b0726f41b5 (diff) | |
Refactored gis/spatialite connection initialization
The connection state is now initialized in get_new_connection().
Refs #19274.
| -rw-r--r-- | django/contrib/gis/db/backends/spatialite/base.py | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/django/contrib/gis/db/backends/spatialite/base.py b/django/contrib/gis/db/backends/spatialite/base.py index b447d1d9ff..b3a53820c1 100644 --- a/django/contrib/gis/db/backends/spatialite/base.py +++ b/django/contrib/gis/db/backends/spatialite/base.py @@ -36,29 +36,23 @@ class DatabaseWrapper(SQLiteDatabaseWrapper): self.creation = SpatiaLiteCreation(self) self.introspection = SpatiaLiteIntrospection(self) - def _cursor(self): - if self.connection is None: - self._sqlite_create_connection() - - ## From here on, customized for GeoDjango ## - - # Enabling extension loading on the SQLite connection. - try: - self.connection.enable_load_extension(True) - except AttributeError: - raise ImproperlyConfigured('The pysqlite library does not support C extension loading. ' - 'Both SQLite and pysqlite must be configured to allow ' - 'the loading of extensions to use SpatiaLite.' - ) - - # 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 as 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) + def get_new_connection(self, conn_params): + conn = super(DatabaseWrapper, self).get_new_connection(conn_params) + # Enabling extension loading on the SQLite connection. + try: + conn.enable_load_extension(True) + except AttributeError: + raise ImproperlyConfigured( + 'The pysqlite library does not support C extension loading. ' + 'Both SQLite and pysqlite must be configured to allow ' + 'the loading of extensions to use SpatiaLite.') + # Loading the SpatiaLite library extension on the connection, and returning + # the created cursor. + cur = conn.cursor(factory=SQLiteCursorWrapper) + try: + cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,)) + except Exception as msg: + raise ImproperlyConfigured('Unable to load the SpatiaLite library extension ' + '"%s" because: %s' % (self.spatialite_lib, msg)) + cur.close() + return conn |
