Ticket #15169: 15169.1.diff

File 15169.1.diff, 6.1 KB (added by jbronn, 14 years ago)
  • new file django/contrib/gis/db/backends/mysql/compiler.py

    diff -r fe89b6629482 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 fe89b6629482 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 fe89b6629482 django/contrib/gis/db/models/sql/compiler.py
    a b  
    190190                               self.query.extra_select_fields.get(a, None),
    191191                               self.connection)
    192192                  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):
    194195            # We resolve the rest of the columns if we're on Oracle or if
    195196            # the `geo_values` attribute is defined.
    196197            for value, field in map(None, row[index_start:], fields):
  • django/contrib/gis/db/models/sql/query.py

    diff -r fe89b6629482 django/contrib/gis/db/models/sql/query.py
    a b  
    5656        extra selection objects into Geometry and Distance objects.
    5757        TODO: Make converted objects 'lazy' for less overhead.
    5858        """
    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.
    6161            value = super(GeoQuery, self).convert_values(value, field or GeomField(), connection)
    6262
    6363        if value is None:
  • django/contrib/gis/tests/geoapp/models.py

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

    diff -r fe89b6629482 django/contrib/gis/tests/geoapp/test_regress.py
    a b  
    1 import os, unittest
     1from django.test import TestCase
    22from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis, no_spatialite
    33from django.contrib.gis.shortcuts import render_to_kmz
    4 from models import City
     4from models import City, Truth
    55
    6 class GeoRegressionTests(unittest.TestCase):
     6class GeoRegressionTests(TestCase):
    77
    88    def test01_update(self):
    99        "Testing GeoQuerySet.update(), see #10411."
     
    3535        extent = City.objects.filter(name='Pueblo').extent()
    3636        for ref_val, val in zip(ref_ext, extent):
    3737            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)
  • django/db/backends/mysql/base.py

    diff -r fe89b6629482 django/db/backends/mysql/base.py
    a b  
    136136class DatabaseOperations(BaseDatabaseOperations):
    137137    compiler_module = "django.db.backends.mysql.compiler"
    138138
     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
    139145    def date_extract_sql(self, lookup_type, field_name):
    140146        # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
    141147        if lookup_type == 'week_day':
  • django/db/backends/mysql/compiler.py

    diff -r fe89b6629482 django/db/backends/mysql/compiler.py
    a b  
    55        values = []
    66        index_extra_select = len(self.query.extra_select.keys())
    77        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))
    129        return row[:index_extra_select] + tuple(values)
    1310
    1411class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
Back to Top