Ticket #15169: 15169.2.diff

File 15169.2.diff, 4.1 KB (added by Ramiro Morales, 13 years ago)

New attempt, using a strategy similar to the one used by the main MySQL DB backend

  • new file django/contrib/gis/db/backends/mysql/compiler.py

    diff -r 7d7560c39fbd django/contrib/gis/db/backends/mysql/compiler.py
    - +  
     1from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler
     2from django.db.backends.mysql import compiler
     3
     4SQLCompiler = compiler.SQLCompiler
     5
     6class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
     7    pass
     8
     9class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
     10    pass
     11
     12class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
     13    pass
     14
     15class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
     16    pass
     17
     18class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
     19    pass
     20
     21class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
     22    pass
  • django/contrib/gis/db/backends/mysql/operations.py

    diff -r 7d7560c39fbd django/contrib/gis/db/backends/mysql/operations.py
    a b  
    55
    66class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
    77
    8     compiler_module = 'django.contrib.gis.db.models.sql.compiler'
     8    compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
    99    mysql = True
    1010    name = 'mysql'
    1111    select = 'AsText(%s)'
  • django/contrib/gis/db/models/sql/compiler.py

    diff -r 7d7560c39fbd django/contrib/gis/db/models/sql/compiler.py
    a b  
    190190            # the `geo_values` attribute is defined.
    191191            for value, field in map(None, row[index_start:], fields):
    192192                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)
    193199        else:
    194200            values.extend(row[index_start:])
    195201        return tuple(values)
  • django/contrib/gis/tests/geoapp/models.py

    diff -r 7d7560c39fbd django/contrib/gis/tests/geoapp/models.py
    a b  
    3434    objects = models.GeoManager()
    3535    def __unicode__(self): return self.name
    3636
     37class Truth(models.Model):
     38    val = models.BooleanField()
     39    objects = models.GeoManager()
     40
    3741if not spatialite:
    3842    class Feature(models.Model):
    3943        name = models.CharField(max_length=20)
  • django/contrib/gis/tests/geoapp/test_regress.py

    diff -r 7d7560c39fbd django/contrib/gis/tests/geoapp/test_regress.py
    a b  
    77from django.db.models import Count
    88from django.test import TestCase
    99
    10 from .models import City, PennsylvaniaCity, State
     10from .models import City, PennsylvaniaCity, State, Truth
    1111
    1212
    1313class GeoRegressionTests(TestCase):
     
    6464        "Regression for #16409 - make sure defer() and only() work with annotate()"
    6565        self.assertIsInstance(list(City.objects.annotate(Count('point')).defer('name')), list)
    6666        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)
Back to Top