diff -r fe89b6629482 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 fe89b6629482 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 fe89b6629482 django/contrib/gis/db/models/sql/compiler.py
a
|
b
|
|
190 | 190 | self.query.extra_select_fields.get(a, None), |
191 | 191 | self.connection) |
192 | 192 | for v, a in izip(row[rn_offset:index_start], aliases)] |
193 | | if self.connection.ops.oracle or getattr(self.query, 'geo_values', False): |
| 193 | |
| 194 | if self.connection.ops.oracle or self.connection.ops.mysql or getattr(self.query, 'geo_values', False): |
194 | 195 | # We resolve the rest of the columns if we're on Oracle or if |
195 | 196 | # the `geo_values` attribute is defined. |
196 | 197 | for value, field in map(None, row[index_start:], fields): |
diff -r fe89b6629482 django/contrib/gis/db/models/sql/query.py
a
|
b
|
|
56 | 56 | extra selection objects into Geometry and Distance objects. |
57 | 57 | TODO: Make converted objects 'lazy' for less overhead. |
58 | 58 | """ |
59 | | if connection.ops.oracle: |
60 | | # Running through Oracle's first. |
| 59 | if connection.ops.oracle or connection.ops.mysql: |
| 60 | # On MySQL and Oracle, call their version of `convert_values` first. |
61 | 61 | value = super(GeoQuery, self).convert_values(value, field or GeomField(), connection) |
62 | 62 | |
63 | 63 | if value is None: |
diff -r fe89b6629482 django/contrib/gis/tests/geoapp/models.py
a
|
b
|
|
33 | 33 | objects = models.GeoManager() |
34 | 34 | def __unicode__(self): return self.name |
35 | 35 | |
| 36 | class Truth(models.Model): |
| 37 | val = models.BooleanField() |
| 38 | objects = models.GeoManager() |
| 39 | |
36 | 40 | if not spatialite: |
37 | 41 | class Feature(models.Model): |
38 | 42 | name = models.CharField(max_length=20) |
diff -r fe89b6629482 django/contrib/gis/tests/geoapp/test_regress.py
a
|
b
|
|
1 | | import os, unittest |
| 1 | from django.test import TestCase |
2 | 2 | from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis, no_spatialite |
3 | 3 | from django.contrib.gis.shortcuts import render_to_kmz |
4 | | from models import City |
| 4 | from models import City, Truth |
5 | 5 | |
6 | | class GeoRegressionTests(unittest.TestCase): |
| 6 | class GeoRegressionTests(TestCase): |
7 | 7 | |
8 | 8 | def test01_update(self): |
9 | 9 | "Testing GeoQuerySet.update(), see #10411." |
… |
… |
|
35 | 35 | extent = City.objects.filter(name='Pueblo').extent() |
36 | 36 | for ref_val, val in zip(ref_ext, extent): |
37 | 37 | self.assertAlmostEqual(ref_val, val, 4) |
| 38 | |
| 39 | def test04_boolean_conversion(self): |
| 40 | "Testing Boolean value conversion with the spatial backend, see #15169." |
| 41 | t1 = Truth.objects.create(val=True) |
| 42 | t2 = Truth.objects.create(val=False) |
| 43 | |
| 44 | self.assertTrue(Truth.objects.get(pk=1).val is True) |
| 45 | self.assertTrue(Truth.objects.get(pk=2).val is False) |
diff -r fe89b6629482 django/db/backends/mysql/base.py
a
|
b
|
|
136 | 136 | class DatabaseOperations(BaseDatabaseOperations): |
137 | 137 | compiler_module = "django.db.backends.mysql.compiler" |
138 | 138 | |
| 139 | def convert_values(self, value, field): |
| 140 | if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and |
| 141 | value in (0, 1)): |
| 142 | value = bool(value) |
| 143 | return value |
| 144 | |
139 | 145 | def date_extract_sql(self, lookup_type, field_name): |
140 | 146 | # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html |
141 | 147 | if lookup_type == 'week_day': |
diff -r fe89b6629482 django/db/backends/mysql/compiler.py
a
|
b
|
|
5 | 5 | values = [] |
6 | 6 | index_extra_select = len(self.query.extra_select.keys()) |
7 | 7 | for value, field in map(None, row[index_extra_select:], fields): |
8 | | if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and |
9 | | value in (0, 1)): |
10 | | value = bool(value) |
11 | | values.append(value) |
| 8 | values.append(self.query.convert_values(value, field, connection=self.connection)) |
12 | 9 | return row[:index_extra_select] + tuple(values) |
13 | 10 | |
14 | 11 | class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler): |