1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

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
This commit is contained in:
Ramiro Morales
2012-02-11 00:40:18 +00:00
parent 4768f39c95
commit c406b554c7
2 changed files with 54 additions and 22 deletions

View File

@@ -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