Loading django/db/backends/oracle/compiler.py +11 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading django/db/models/sql/compiler.py +7 −5 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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. Loading @@ -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() Loading Loading @@ -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) Loading django/db/models/sql/subqueries.py +4 −1 Original line number Diff line number Diff line Loading @@ -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, ) docs/releases/1.8.txt +3 −0 Original line number Diff line number Diff line Loading @@ -938,6 +938,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` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loading Loading
django/db/backends/oracle/compiler.py +11 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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. Loading
django/db/models/sql/compiler.py +7 −5 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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. Loading @@ -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() Loading Loading @@ -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) Loading
django/db/models/sql/subqueries.py +4 −1 Original line number Diff line number Diff line Loading @@ -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, )
docs/releases/1.8.txt +3 −0 Original line number Diff line number Diff line Loading @@ -938,6 +938,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` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loading