diff -r 7d7560c39fbd django/contrib/gis/db/backends/mysql/compiler.py
-
|
+
|
|
| 1 | from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler |
| 2 | from django.db.backends.mysql import compiler |
| 3 | |
| 4 | SQLCompiler = compiler.SQLCompiler |
| 5 | |
| 6 | class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler): |
| 7 | pass |
| 8 | |
| 9 | class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): |
| 10 | pass |
| 11 | |
| 12 | class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): |
| 13 | pass |
| 14 | |
| 15 | class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): |
| 16 | pass |
| 17 | |
| 18 | class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): |
| 19 | pass |
| 20 | |
| 21 | class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): |
| 22 | pass |
diff -r 7d7560c39fbd django/contrib/gis/db/backends/mysql/operations.py
a
|
b
|
|
5 | 5 | |
6 | 6 | class MySQLOperations(DatabaseOperations, BaseSpatialOperations): |
7 | 7 | |
8 | | compiler_module = 'django.contrib.gis.db.models.sql.compiler' |
| 8 | compiler_module = 'django.contrib.gis.db.backends.mysql.compiler' |
9 | 9 | mysql = True |
10 | 10 | name = 'mysql' |
11 | 11 | select = 'AsText(%s)' |
diff -r 7d7560c39fbd django/contrib/gis/db/models/sql/compiler.py
a
|
b
|
|
190 | 190 | # the `geo_values` attribute is defined. |
191 | 191 | for value, field in map(None, row[index_start:], fields): |
192 | 192 | values.append(self.query.convert_values(value, field, self.connection)) |
| 193 | elif self.connection.ops.mysql or getattr(self.query, 'geo_values', False): |
| 194 | for value, field in map(None, row[index_start:], fields): |
| 195 | if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and |
| 196 | value in (0, 1)): |
| 197 | value = bool(value) |
| 198 | values.append(value) |
193 | 199 | else: |
194 | 200 | values.extend(row[index_start:]) |
195 | 201 | return tuple(values) |
diff -r 7d7560c39fbd django/contrib/gis/tests/geoapp/models.py
a
|
b
|
|
34 | 34 | objects = models.GeoManager() |
35 | 35 | def __unicode__(self): return self.name |
36 | 36 | |
| 37 | class Truth(models.Model): |
| 38 | val = models.BooleanField() |
| 39 | objects = models.GeoManager() |
| 40 | |
37 | 41 | if not spatialite: |
38 | 42 | class Feature(models.Model): |
39 | 43 | name = models.CharField(max_length=20) |
diff -r 7d7560c39fbd django/contrib/gis/tests/geoapp/test_regress.py
a
|
b
|
|
7 | 7 | from django.db.models import Count |
8 | 8 | from django.test import TestCase |
9 | 9 | |
10 | | from .models import City, PennsylvaniaCity, State |
| 10 | from .models import City, PennsylvaniaCity, State, Truth |
11 | 11 | |
12 | 12 | |
13 | 13 | class GeoRegressionTests(TestCase): |
… |
… |
|
64 | 64 | "Regression for #16409 - make sure defer() and only() work with annotate()" |
65 | 65 | self.assertIsInstance(list(City.objects.annotate(Count('point')).defer('name')), list) |
66 | 66 | self.assertIsInstance(list(City.objects.annotate(Count('point')).only('name')), list) |
| 67 | |
| 68 | def test07_boolean_conversion(self): |
| 69 | "Testing Boolean value conversion with the spatial backend, see #15169." |
| 70 | t1 = Truth.objects.create(val=True) |
| 71 | t2 = Truth.objects.create(val=False) |
| 72 | |
| 73 | val1 = Truth.objects.get(pk=1).val |
| 74 | val2 = Truth.objects.get(pk=2).val |
| 75 | # verify types -- should't be 0/1 |
| 76 | self.assertIsInstance(val1, bool) |
| 77 | self.assertIsInstance(val2, bool) |
| 78 | # verify values |
| 79 | self.assertEqual(val1, True) |
| 80 | self.assertEqual(val2, False) |