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

Method as_sql

django/db/models/sql/compiler.py:2007–2029  ·  view source on GitHub ↗

Create the SQL for this query. Return the SQL string and list of parameters.

(self)

Source from the content-addressed store, hash-verified

2005 return f"{delete} WHERE {where}", tuple(params)
2006
2007 def as_sql(self):
2008 """
2009 Create the SQL for this query. Return the SQL string and list of
2010 parameters.
2011 """
2012 if self.single_alias and (
2013 self.connection.features.delete_can_self_reference_subquery
2014 or not self.contains_self_reference_subquery
2015 ):
2016 return self._as_sql(self.query)
2017 innerq = self.query.clone()
2018 innerq.__class__ = Query
2019 innerq.clear_select_clause()
2020 pk = self.query.model._meta.pk
2021 innerq.select = [pk.get_col(self.query.get_initial_alias())]
2022 outerq = Query(self.query.model)
2023 if not self.connection.features.update_can_self_select:
2024 # Force the materialization of the inner query to allow reference
2025 # to the target table on MySQL.
2026 sql, params = innerq.get_compiler(connection=self.connection).as_sql()
2027 innerq = RawSQL("SELECT * FROM (%s) subquery" % sql, params)
2028 outerq.add_filter("pk__in", innerq)
2029 return self._as_sql(outerq)
2030
2031
2032class SQLUpdateCompiler(SQLCompiler):

Callers

nothing calls this directly

Calls 10

_as_sqlMethod · 0.95
add_filterMethod · 0.95
QueryClass · 0.90
RawSQLClass · 0.90
clear_select_clauseMethod · 0.80
get_initial_aliasMethod · 0.80
get_compilerMethod · 0.80
cloneMethod · 0.45
get_colMethod · 0.45
as_sqlMethod · 0.45

Tested by

no test coverage detected