Code

Ticket #17756: patch-feb2312@1646.diff

File patch-feb2312@1646.diff, 4.4 KB (added by danols, 2 years ago)

Code + Doc patch

Line 
1Index: docs/ref/contrib/gis/install.txt
2===================================================================
3--- docs/ref/contrib/gis/install.txt    (revision 17579)
4+++ docs/ref/contrib/gis/install.txt    (working copy)
5@@ -64,7 +64,7 @@
6 PostgreSQL          GEOS, PROJ.4, PostGIS           8.1+                Requires PostGIS.
7 MySQL               GEOS                            5.x                 Not OGC-compliant; limited functionality.
8 Oracle              GEOS                            10.2, 11            XE not supported; not tested with 9.
9-SQLite              GEOS, GDAL, PROJ.4, SpatiaLite  3.6.+               Requires SpatiaLite 2.3+, pysqlite2 2.5+, and Django 1.1.
10+SQLite              GEOS, GDAL, PROJ.4, SpatiaLite  3.6.+               Requires SpatiaLite 2.3+, pyspatialite2.6+ OR pysqlite2 2.5+
11 ==================  ==============================  ==================  ==========================================================
12
13 .. _geospatial_libs:
14@@ -459,9 +459,20 @@
15
16 .. _pysqlite2:
17
18+
19+pyspatialite
20+^^^^^^^^^^^^
21+
22+Based almost entirely on pysqlite, this module primarily does one thing different: it build's it's own copy
23+of sqlite with spatialite built in.The simplest way to install is to use python package installer PIP:
24+
25+    $ pip install pyspatialite
26+
27 pysqlite2
28 ^^^^^^^^^
29
30+NOTE: Skip this step if you have already installed pyspatialite
31+
32 Because SpatiaLite must be loaded as an external extension, it requires the
33 ``enable_load_extension`` method, which is only available in versions 2.5+.
34 Thus, download pysqlite2 2.6, and untar::
35Index: django/db/backends/sqlite3/base.py
36===================================================================
37--- django/db/backends/sqlite3/base.py  (revision 17579)
38+++ django/db/backends/sqlite3/base.py  (working copy)
39@@ -22,13 +22,16 @@
40 from django.utils.timezone import is_aware, is_naive, utc
41
42 try:
43+    from pyspatialite import dbapi2 as Database
44+except ImportError, exc:
45     try:
46         from pysqlite2 import dbapi2 as Database
47-    except ImportError, e1:
48-        from sqlite3 import dbapi2 as Database
49-except ImportError, exc:
50-    from django.core.exceptions import ImproperlyConfigured
51-    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
52+    except ImportError, exc:
53+        try:
54+            from sqlite3 import dbapi2 as Database
55+        except ImportError, exc:
56+            from django.core.exceptions import ImproperlyConfigured
57+            raise ImproperlyConfigured("Error loading either pyspatialite, pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
58
59
60 DatabaseError = Database.DatabaseError
61@@ -337,7 +340,7 @@
62             raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
63
64     def convert_query(self, query):
65-        return FORMAT_QMARK_REGEX.sub('?', query).replace('%%','%')
66+        return FORMAT_QMARK_REGEX.sub('?', query).replace('%%', '%')
67
68 def _sqlite_extract(lookup_type, dt):
69     if dt is None:
70Index: django/contrib/gis/db/backends/spatialite/base.py
71===================================================================
72--- django/contrib/gis/db/backends/spatialite/base.py   (revision 17579)
73+++ django/contrib/gis/db/backends/spatialite/base.py   (working copy)
74@@ -15,7 +15,7 @@
75     def __init__(self, *args, **kwargs):
76         # Before we get too far, make sure pysqlite 2.5+ is installed.
77         if Database.version_info < (2, 5, 0):
78-            raise ImproperlyConfigured('Only versions of pysqlite 2.5+ are '
79+            raise ImproperlyConfigured('Only versions of pyspatialite 2.6+ or pysqlite 2.5+ are '
80                                        'compatible with SpatiaLite and GeoDjango.')
81
82         # Trying to find the location of the SpatiaLite library.
83@@ -47,7 +47,7 @@
84                 self.connection.enable_load_extension(True)
85             except AttributeError:
86                 raise ImproperlyConfigured('The pysqlite library does not support C extension loading. '
87-                                           'Both SQLite and pysqlite must be configured to allow '
88+                                           'Install pyspatialite or configure SQLite and pysqlite to allow '
89                                            'the loading of extensions to use SpatiaLite.'
90                                            )
91