diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2012-02-11 00:40:18 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2012-02-11 00:40:18 +0000 |
| commit | c406b554c76ec57bbeddea090a7ca1a4f1f6daa9 (patch) | |
| tree | a95771b38a00a245d9f16b33dc2df40f23fee0d7 /django | |
| parent | 4768f39c95ea702788eafe86c6206fb605773965 (diff) | |
Added, documented support for SpatiaLite 3.0 to GeoDjango.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17496 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/gis/db/backends/spatialite/creation.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py index 03ea45da44..ce46d5b7a3 100644 --- a/django/contrib/gis/db/backends/spatialite/creation.py +++ b/django/contrib/gis/db/backends/spatialite/creation.py @@ -102,21 +102,30 @@ class SpatiaLiteCreation(DatabaseCreation): """ This routine loads up the SpatiaLite SQL file. """ - # Getting the location of the SpatiaLite SQL file, and confirming - # it exists. - spatialite_sql = self.spatialite_init_file() - if not os.path.isfile(spatialite_sql): - raise ImproperlyConfigured('Could not find the required SpatiaLite initialization ' - 'SQL file (necessary for testing): %s' % spatialite_sql) - - # Opening up the SpatiaLite SQL initialization file and executing - # as a script. - sql_fh = open(spatialite_sql, 'r') - try: + if self.connection.ops.spatial_version[:2] >= (3, 0): + # Spatialite >= 3.0.x -- No ned to load any SQL file, calling + # InitSpatialMetaData() transparently creates the spatial metadata + # tables cur = self.connection._cursor() - cur.executescript(sql_fh.read()) - finally: - sql_fh.close() + cur.execute("SELECT InitSpatialMetaData()") + else: + # Spatialite < 3.0.x -- Load the initial SQL + + # Getting the location of the SpatiaLite SQL file, and confirming + # it exists. + spatialite_sql = self.spatialite_init_file() + if not os.path.isfile(spatialite_sql): + raise ImproperlyConfigured('Could not find the required SpatiaLite initialization ' + 'SQL file (necessary for testing): %s' % spatialite_sql) + + # Opening up the SpatiaLite SQL initialization file and executing + # as a script. + sql_fh = open(spatialite_sql, 'r') + try: + cur = self.connection._cursor() + cur.executescript(sql_fh.read()) + finally: + sql_fh.close() def spatialite_init_file(self): # SPATIALITE_SQL may be placed in settings to tell GeoDjango |
