MCPcopy
hub / github.com/django/django / as_sql

Method as_sql

django/db/backends/mysql/compiler.py:18–41  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

16
17class SQLDeleteCompiler(BaseSQLDeleteCompiler):
18 def as_sql(self):
19 # Prefer the non-standard DELETE FROM syntax over the SQL generated by
20 # the SQLDeleteCompiler's default implementation when multiple tables
21 # are involved since MySQL/MariaDB will generate a more efficient query
22 # plan than when using a subquery.
23 where, having, qualify = self.query.where.split_having_qualify(
24 must_group_by=self.query.group_by is not None
25 )
26 if self.single_alias or having or qualify:
27 # DELETE FROM cannot be used when filtering against aggregates or
28 # window functions as it doesn't allow for GROUP BY/HAVING clauses
29 # and the subquery wrapping (necessary to emulate QUALIFY).
30 return super().as_sql()
31 result = ["DELETE %s FROM" % self.quote_name(self.query.get_initial_alias())]
32 from_sql, params = self.get_from_clause()
33 result.extend(from_sql)
34 try:
35 where_sql, where_params = self.compile(where)
36 except FullResultSet:
37 pass
38 else:
39 result.append("WHERE %s" % where_sql)
40 params.extend(where_params)
41 return " ".join(result), tuple(params)
42
43
44class SQLUpdateCompiler(BaseSQLUpdateCompiler):

Callers 1

as_sqlMethod · 0.45

Calls 8

split_having_qualifyMethod · 0.80
get_initial_aliasMethod · 0.80
get_from_clauseMethod · 0.80
extendMethod · 0.80
quote_nameMethod · 0.45
compileMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected