Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Carl Meyer authored March 02, 2012
32  django/contrib/gis/db/backends/mysql/compiler.py
... ...
@@ -0,0 +1,32 @@
  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
+    def resolve_columns(self, row, fields=()):
  8
+        """
  9
+        Integrate the cases handled both by the base GeoSQLCompiler and the
  10
+        main MySQL compiler (converting 0/1 to True/False for boolean fields).
  11
+
  12
+        Refs #15169.
  13
+
  14
+        """
  15
+        row = BaseGeoSQLCompiler.resolve_columns(self, row, fields)
  16
+        return SQLCompiler.resolve_columns(self, row, fields)
  17
+
  18
+
  19
+class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
  20
+    pass
  21
+
  22
+class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
  23
+    pass
  24
+
  25
+class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
  26
+    pass
  27
+
  28
+class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
  29
+    pass
  30
+
  31
+class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
  32
+    pass
2  django/contrib/gis/db/backends/mysql/operations.py
@@ -5,7 +5,7 @@
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)'
4  django/contrib/gis/tests/geoapp/models.py
@@ -34,6 +34,10 @@ class Track(models.Model):
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)
16  django/contrib/gis/tests/geoapp/test_regress.py
@@ -7,7 +7,7 @@
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,3 +64,17 @@ def test06_defer_or_only_with_annotate(self):
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)

0 notes on commit b9bf7cc

Please sign in to comment.
Something went wrong with that request. Please try again.