Fixed `F()` expression regressions in GeoDjango caused by recent datastructure changes in `SQLEvaluator`.

This commit is contained in:
Justin Bronn 2012-10-05 18:41:50 -07:00
parent 84f9741664
commit cd99c12f05
5 changed files with 14 additions and 4 deletions

View File

@ -116,6 +116,16 @@ class BaseSpatialOperations(object):
""" """
raise NotImplementedError raise NotImplementedError
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 # Spatial SQL Construction
def spatial_aggregate_sql(self, agg): def spatial_aggregate_sql(self, agg):
raise NotImplementedError('Aggregate support not implemented for this spatial backend.') raise NotImplementedError('Aggregate support not implemented for this spatial backend.')

View File

@ -44,7 +44,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
modify the placeholder based on the contents of the given value. modify the placeholder based on the contents of the given value.
""" """
if hasattr(value, 'expression'): if hasattr(value, 'expression'):
placeholder = '%s.%s' % tuple(map(self.quote_name, value.cols[value.expression])) placeholder = placeholder % self.get_expression_column(value)
else: else:
placeholder = '%s(%%s)' % self.from_text placeholder = '%s(%%s)' % self.from_text
return placeholder return placeholder

View File

@ -213,7 +213,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
placeholder = '%s' placeholder = '%s'
# No geometry value used for F expression, substitue in # No geometry value used for F expression, substitue in
# the column name instead. # the column name instead.
return placeholder % '%s.%s' % tuple(map(self.quote_name, value.cols[value.expression])) return placeholder % self.get_expression_column(value)
else: else:
if transform_value(value, f.srid): if transform_value(value, f.srid):
return '%s(SDO_GEOMETRY(%%s, %s), %s)' % (self.transform, value.srid, f.srid) return '%s(SDO_GEOMETRY(%%s, %s), %s)' % (self.transform, value.srid, f.srid)

View File

@ -381,7 +381,7 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
# If this is an F expression, then we don't really want # If this is an F expression, then we don't really want
# a placeholder and instead substitute in the column # a placeholder and instead substitute in the column
# of the expression. # of the expression.
placeholder = placeholder % '%s.%s' % tuple(map(self.quote_name, value.cols[value.expression])) placeholder = placeholder % self.get_expression_column(value)
return placeholder return placeholder

View File

@ -208,7 +208,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
placeholder = '%s' placeholder = '%s'
# No geometry value used for F expression, substitue in # No geometry value used for F expression, substitue in
# the column name instead. # the column name instead.
return placeholder % '%s.%s' % tuple(map(self.quote_name, value.cols[value.expression])) return placeholder % self.get_expression_column(value)
else: else:
if transform_value(value, f.srid): if transform_value(value, f.srid):
# Adding Transform() to the SQL placeholder. # Adding Transform() to the SQL placeholder.