Commit f59fd15c authored by Josh Smeaton's avatar Josh Smeaton Committed by Marc Tamlyn
Browse files

Fixed #14030 -- Allowed annotations to accept all expressions

parent 39e3ef88
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -347,6 +347,7 @@ answer newbie questions, and generally made Django that much better:
    Jorge Bastida <me@jorgebastida.com>
    Jorge Gajon <gajon@gajon.org>
    Joseph Kocherhans <joseph@jkocherhans.com>
    Josh Smeaton <josh.smeaton@gmail.com>
    Joshua Ginsberg <jag@flowtheory.net>
    Jozko Skrablin <jozko.skrablin@gmail.com>
    J. Pablo Fernandez <pupeno@pupeno.com>
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ from django.db.models import signals, FieldDoesNotExist, DO_NOTHING
from django.db.models.base import ModelBase
from django.db.models.fields.related import ForeignObject, ForeignObjectRel
from django.db.models.related import PathInfo
from django.db.models.sql.datastructures import Col
from django.db.models.expressions import Col
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import smart_text, python_2_unicode_compatible

+1 −11
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ class BaseSpatialOperations(object):
        """
        raise NotImplementedError('Distance operations not available on this spatial backend.')

    def get_geom_placeholder(self, f, value):
    def get_geom_placeholder(self, f, value, qn):
        """
        Returns the placeholder for the given geometry field with the given
        value.  Depending on the spatial backend, the placeholder may contain a
@@ -195,16 +195,6 @@ class BaseSpatialOperations(object):
        """
        raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_placeholder() method')

    def get_expression_column(self, evaluator):
        """
        Helper method to return the quoted column string from the evaluator
        for its expression.
        """
        for expr, col_tup in evaluator.cols:
            if expr is evaluator.expression:
                return '%s.%s' % tuple(map(self.quote_name, col_tup))
        raise Exception("Could not find the column for the expression.")

    # Spatial SQL Construction
    def spatial_aggregate_sql(self, agg):
        raise NotImplementedError('Aggregate support not implemented for this spatial backend.')
+3 −3
Original line number Diff line number Diff line
@@ -35,14 +35,14 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
    def geo_db_type(self, f):
        return f.geom_type

    def get_geom_placeholder(self, f, value):
    def get_geom_placeholder(self, f, value, qn):
        """
        The placeholder here has to include MySQL's WKT constructor.  Because
        MySQL does not support spatial transformations, there is no need to
        modify the placeholder based on the contents of the given value.
        """
        if hasattr(value, 'expression'):
            placeholder = self.get_expression_column(value)
        if hasattr(value, 'as_sql'):
            placeholder, _ = qn.compile(value)
        else:
            placeholder = '%s(%%s)' % self.from_text
        return placeholder
+12 −9
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
"""
import re

from django.db.backends.oracle.base import DatabaseOperations
from django.db.backends.oracle.base import DatabaseOperations, Database
from django.contrib.gis.db.backends.base import BaseSpatialOperations
from django.contrib.gis.db.backends.oracle.adapter import OracleSpatialAdapter
from django.contrib.gis.db.backends.utils import SpatialOperator
@@ -145,9 +145,11 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
        else:
            return None

    def convert_geom(self, clob, geo_field):
        if clob:
            return Geometry(clob.read(), geo_field.srid)
    def convert_geom(self, value, geo_field):
        if value:
            if isinstance(value, Database.LOB):
                value = value.read()
            return Geometry(value, geo_field.srid)
        else:
            return None

@@ -184,7 +186,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):

        return [dist_param]

    def get_geom_placeholder(self, f, value):
    def get_geom_placeholder(self, f, value, qn):
        """
        Provides a proper substitution value for Geometries that are not in the
        SRID of the field.  Specifically, this routine will substitute in the
@@ -196,14 +198,15 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
        def transform_value(val, srid):
            return val.srid != srid

        if hasattr(value, 'expression'):
        if hasattr(value, 'as_sql'):
            if transform_value(value, f.srid):
                placeholder = '%s(%%s, %s)' % (self.transform, f.srid)
            else:
                placeholder = '%s'
            # No geometry value used for F expression, substitute in
            # the column name instead.
            return placeholder % self.get_expression_column(value)
            sql, _ = qn.compile(value)
            return placeholder % sql
        else:
            if transform_value(value, f.srid):
                return '%s(SDO_GEOMETRY(%%s, %s), %s)' % (self.transform, value.srid, f.srid)
@@ -219,9 +222,9 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
        if agg_name == 'union':
            agg_name += 'agg'
        if agg.is_extent:
            sql_template = '%(function)s(%(field)s)'
            sql_template = '%(function)s(%(expressions)s)'
        else:
            sql_template = '%(function)s(SDOAGGRTYPE(%(field)s,%(tolerance)s))'
            sql_template = '%(function)s(SDOAGGRTYPE(%(expressions)s,%(tolerance)s))'
        sql_function = getattr(self, agg_name)
        return self.select % sql_template, sql_function

Loading