diff options
| author | Raphael Gaschignard <raphael@rtpg.co> | 2024-11-19 14:50:24 +1000 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-03 15:07:02 +0100 |
| commit | ddefc3fed1cf1f0d3fab455babbbc009b76e4196 (patch) | |
| tree | 0e6084422b038e819a825370334fc6da2a55bb7c /django/db/models/query.py | |
| parent | d97cacc2aedf948f7c557d0231e3b410905678b2 (diff) | |
Fixed #35918 -- Added support for execute_sql to directly return row counts.
Diffstat (limited to 'django/db/models/query.py')
| -rw-r--r-- | django/db/models/query.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index e1f785f714..1a44523374 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -26,7 +26,7 @@ from django.db.models.deletion import Collector from django.db.models.expressions import Case, F, Value, When from django.db.models.functions import Cast, Trunc from django.db.models.query_utils import FilteredRelation, Q -from django.db.models.sql.constants import CURSOR, GET_ITERATOR_CHUNK_SIZE +from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE, ROW_COUNT from django.db.models.utils import ( AltersData, create_namedtuple_class, @@ -1209,11 +1209,7 @@ class QuerySet(AltersData): """ query = self.query.clone() query.__class__ = sql.DeleteQuery - cursor = query.get_compiler(using).execute_sql(CURSOR) - if cursor: - with cursor: - return cursor.rowcount - return 0 + return query.get_compiler(using).execute_sql(ROW_COUNT) _raw_delete.alters_data = True @@ -1252,7 +1248,7 @@ class QuerySet(AltersData): # Clear any annotations so that they won't be present in subqueries. query.annotations = {} with transaction.mark_for_rollback_on_error(using=self.db): - rows = query.get_compiler(self.db).execute_sql(CURSOR) + rows = query.get_compiler(self.db).execute_sql(ROW_COUNT) self._result_cache = None return rows @@ -1277,7 +1273,7 @@ class QuerySet(AltersData): # Clear any annotations so that they won't be present in subqueries. query.annotations = {} self._result_cache = None - return query.get_compiler(self.db).execute_sql(CURSOR) + return query.get_compiler(self.db).execute_sql(ROW_COUNT) _update.alters_data = True _update.queryset_only = False |
