mirror of https://github.com/django/django.git
Refs #27624 -- Changed Query.explain_info to namedtuple.
This commit is contained in:
parent
2931d847c2
commit
fc91ea1e50
|
@ -631,10 +631,10 @@ class SQLCompiler:
|
||||||
result.append('HAVING %s' % having)
|
result.append('HAVING %s' % having)
|
||||||
params.extend(h_params)
|
params.extend(h_params)
|
||||||
|
|
||||||
if self.query.explain_query:
|
if self.query.explain_info:
|
||||||
result.insert(0, self.connection.ops.explain_query_prefix(
|
result.insert(0, self.connection.ops.explain_query_prefix(
|
||||||
self.query.explain_format,
|
self.query.explain_info.format,
|
||||||
**self.query.explain_options
|
**self.query.explain_info.options
|
||||||
))
|
))
|
||||||
|
|
||||||
if order_by:
|
if order_by:
|
||||||
|
@ -1247,7 +1247,7 @@ class SQLCompiler:
|
||||||
result = list(self.execute_sql())
|
result = list(self.execute_sql())
|
||||||
# Some backends return 1 item tuples with strings, and others return
|
# Some backends return 1 item tuples with strings, and others return
|
||||||
# tuples with integers and strings. Flatten them out into strings.
|
# tuples with integers and strings. Flatten them out into strings.
|
||||||
output_formatter = json.dumps if self.query.explain_format == 'json' else str
|
output_formatter = json.dumps if self.query.explain_info.format == 'json' else str
|
||||||
for row in result[0]:
|
for row in result[0]:
|
||||||
if not isinstance(row, str):
|
if not isinstance(row, str):
|
||||||
yield ' '.join(output_formatter(c) for c in row)
|
yield ' '.join(output_formatter(c) for c in row)
|
||||||
|
|
|
@ -136,6 +136,9 @@ class RawQuery:
|
||||||
self.cursor.execute(self.sql, params)
|
self.cursor.execute(self.sql, params)
|
||||||
|
|
||||||
|
|
||||||
|
ExplainInfo = namedtuple('ExplainInfo', ('format', 'options'))
|
||||||
|
|
||||||
|
|
||||||
class Query(BaseExpression):
|
class Query(BaseExpression):
|
||||||
"""A single SQL query."""
|
"""A single SQL query."""
|
||||||
|
|
||||||
|
@ -227,9 +230,7 @@ class Query(BaseExpression):
|
||||||
|
|
||||||
self._filtered_relations = {}
|
self._filtered_relations = {}
|
||||||
|
|
||||||
self.explain_query = False
|
self.explain_info = None
|
||||||
self.explain_format = None
|
|
||||||
self.explain_options = {}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def output_field(self):
|
def output_field(self):
|
||||||
|
@ -545,9 +546,7 @@ class Query(BaseExpression):
|
||||||
|
|
||||||
def explain(self, using, format=None, **options):
|
def explain(self, using, format=None, **options):
|
||||||
q = self.clone()
|
q = self.clone()
|
||||||
q.explain_query = True
|
q.explain_info = ExplainInfo(format, options)
|
||||||
q.explain_format = format
|
|
||||||
q.explain_options = options
|
|
||||||
compiler = q.get_compiler(using=using)
|
compiler = q.get_compiler(using=using)
|
||||||
return '\n'.join(compiler.explain_query())
|
return '\n'.join(compiler.explain_query())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue