summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-13 21:42:37 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-13 21:42:37 +0000
commit947ca5123e2e88a2226ed3b39711706d5d609e32 (patch)
treeb0f0d8858570244deb9687ab91e7baa6115cd6b9
parent478926ffdee790bc609418746b8cd72321795eb2 (diff)
Fixed #5030 -- Removed 'COUNT()' from Model.save() when determining whether a row exists. We're now using a SELECT 1 LIMIT 1 instead, as it's more efficient in some databases. Thanks, zigiDev@mac.com and the various folks who verified this patch works
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5882 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/base.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index eb8a9b63be..eced22ab43 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -213,11 +213,11 @@ class Model(object):
record_exists = True
if pk_set:
# Determine whether a record with the primary key already exists.
- cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \
+ cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)),
self._meta.pk.get_db_prep_lookup('exact', pk_val))
# If it does already exist, do an UPDATE.
- if cursor.fetchone()[0] > 0:
+ if cursor.fetchone():
db_values = [f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False)) for f in non_pks]
if db_values:
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \