1
0
mirror of https://github.com/django/django.git synced 2024-12-27 03:25:58 +00:00

[1.8.x] Fixed #24164 -- Fixed Oracle GIS limited aggregation test failure.

Backport of 29c0073335 from master
This commit is contained in:
Tim Graham 2015-01-29 07:20:56 -05:00
parent a301061f88
commit df68751134
4 changed files with 25 additions and 12 deletions

View File

@ -2,7 +2,7 @@ from django.db.models.sql import compiler
class SQLCompiler(compiler.SQLCompiler):
def as_sql(self, with_limits=True, with_col_aliases=False):
def as_sql(self, with_limits=True, with_col_aliases=False, subquery=False):
"""
Creates the SQL for this query. Returns the SQL string and list
of parameters. This is overridden from the original Query class
@ -20,12 +20,17 @@ class SQLCompiler(compiler.SQLCompiler):
do_offset = with_limits and (self.query.high_mark is not None
or self.query.low_mark)
if not do_offset:
sql, params = super(SQLCompiler, self).as_sql(with_limits=False,
with_col_aliases=with_col_aliases)
sql, params = super(SQLCompiler, self).as_sql(
with_limits=False,
with_col_aliases=with_col_aliases,
subquery=subquery,
)
else:
sql, params = super(SQLCompiler, self).as_sql(with_limits=False,
with_col_aliases=True)
sql, params = super(SQLCompiler, self).as_sql(
with_limits=False,
with_col_aliases=True,
subquery=subquery,
)
# Wrap the base query in an outer SELECT * with boundaries on
# the "_RN" column. This is the canonical way to emulate LIMIT
# and OFFSET on Oracle.

View File

@ -30,6 +30,7 @@ class SQLCompiler(object):
self.annotation_col_map = None
self.klass_info = None
self.ordering_parts = re.compile(r'(.*)\s(ASC|DESC)(.*)')
self.subquery = False
def setup_query(self):
if all(self.query.alias_refcount[a] == 0 for a in self.query.tables):
@ -342,11 +343,11 @@ class SQLCompiler(object):
sql, params = vendor_impl(self, self.connection)
else:
sql, params = node.as_sql(self, self.connection)
if select_format:
if select_format and not self.subquery:
return node.output_field.select_format(self, sql, params)
return sql, params
def as_sql(self, with_limits=True, with_col_aliases=False):
def as_sql(self, with_limits=True, with_col_aliases=False, subquery=False):
"""
Creates the SQL for this query. Returns the SQL string and list of
parameters.
@ -359,6 +360,7 @@ class SQLCompiler(object):
# However we do not want to get rid of stuff done in pre_sql_setup(),
# as the pre_sql_setup will modify query state in a way that forbids
# another run of it.
self.subquery = subquery
refcounts_before = self.query.alias_refcount.copy()
try:
extra_select, order_by, group_by = self.pre_sql_setup()
@ -1115,9 +1117,9 @@ class SQLAggregateCompiler(SQLCompiler):
raise EmptyResultSet
sql, params = [], []
for annotation in self.query.annotation_select.values():
agg_sql, agg_params = self.compile(annotation)
sql.append(agg_sql)
params.extend(agg_params)
ann_sql, ann_params = self.compile(annotation, select_format=True)
sql.append(ann_sql)
params.extend(ann_params)
self.col_count = len(self.query.annotation_select)
sql = ', '.join(sql)
params = tuple(params)

View File

@ -209,4 +209,7 @@ class AggregateQuery(Query):
compiler = 'SQLAggregateCompiler'
def add_subquery(self, query, using):
self.subquery, self.sub_params = query.get_compiler(using).as_sql(with_col_aliases=True)
self.subquery, self.sub_params = query.get_compiler(using).as_sql(
with_col_aliases=True,
subquery=True,
)

View File

@ -937,6 +937,9 @@ those writing third-party backends in updating their code:
``data_type_check_constraints`` attributes have moved from the
``DatabaseCreation`` class to ``DatabaseWrapper``.
* The ``SQLCompiler.as_sql()`` method now takes a ``subquery`` parameter
(:ticket:`24164`).
:mod:`django.contrib.admin`
~~~~~~~~~~~~~~~~~~~~~~~~~~~