Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #15169 -- Added conversion of 0/1 to False/True for MySQL GIS b…

…ackend. Thanks zmsmith for report, and Ramiro for draft patch and review.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17632 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b9bf7cce896a4886f77b2162042a6fb676463b86 1 parent 89b57a7
@carljm carljm authored
View
32 django/contrib/gis/db/backends/mysql/compiler.py
@@ -0,0 +1,32 @@
+from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler
+from django.db.backends.mysql import compiler
+
+SQLCompiler = compiler.SQLCompiler
+
+class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
+ def resolve_columns(self, row, fields=()):
+ """
+ Integrate the cases handled both by the base GeoSQLCompiler and the
+ main MySQL compiler (converting 0/1 to True/False for boolean fields).
+
+ Refs #15169.
+
+ """
+ row = BaseGeoSQLCompiler.resolve_columns(self, row, fields)
+ return SQLCompiler.resolve_columns(self, row, fields)
+
+
+class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
+ pass
+
+class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
+ pass
+
+class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
+ pass
+
+class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
+ pass
+
+class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
+ pass
View
2  django/contrib/gis/db/backends/mysql/operations.py
@@ -5,7 +5,7 @@
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
- compiler_module = 'django.contrib.gis.db.models.sql.compiler'
+ compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
mysql = True
name = 'mysql'
select = 'AsText(%s)'
View
4 django/contrib/gis/tests/geoapp/models.py
@@ -34,6 +34,10 @@ class Track(models.Model):
objects = models.GeoManager()
def __unicode__(self): return self.name
+class Truth(models.Model):
+ val = models.BooleanField()
+ objects = models.GeoManager()
+
if not spatialite:
class Feature(models.Model):
name = models.CharField(max_length=20)
View
16 django/contrib/gis/tests/geoapp/test_regress.py
@@ -7,7 +7,7 @@
from django.db.models import Count
from django.test import TestCase
-from .models import City, PennsylvaniaCity, State
+from .models import City, PennsylvaniaCity, State, Truth
class GeoRegressionTests(TestCase):
@@ -64,3 +64,17 @@ def test06_defer_or_only_with_annotate(self):
"Regression for #16409. Make sure defer() and only() work with annotate()"
self.assertIsInstance(list(City.objects.annotate(Count('point')).defer('name')), list)
self.assertIsInstance(list(City.objects.annotate(Count('point')).only('name')), list)
+
+ def test07_boolean_conversion(self):
+ "Testing Boolean value conversion with the spatial backend, see #15169."
+ t1 = Truth.objects.create(val=True)
+ t2 = Truth.objects.create(val=False)
+
+ val1 = Truth.objects.get(pk=1).val
+ val2 = Truth.objects.get(pk=2).val
+ # verify types -- should't be 0/1
+ self.assertIsInstance(val1, bool)
+ self.assertIsInstance(val2, bool)
+ # verify values
+ self.assertEqual(val1, True)
+ self.assertEqual(val2, False)
Please sign in to comment.
Something went wrong with that request. Please try again.