(self)
| 16 | |
| 17 | class 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 | |
| 44 | class SQLUpdateCompiler(BaseSQLUpdateCompiler): |
no test coverage detected