1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[boulder-oracle-sprint] Replaced Oracle-specific LIMIT 1 for existence test with a generic SELECT COUNT(*)

git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@3990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2006-11-04 22:19:44 +00:00
parent e715476a9f
commit 39fd198ddd

View File

@ -171,11 +171,10 @@ class Model(object):
record_exists = True
if pk_set:
# Determine whether a record with the primary key already exists.
lim = settings.DATABASE_ENGINE != 'oracle' and ' LIMIT 1' or ''
cursor.execute("SELECT 1 FROM %s WHERE %s=%%s %s" % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), lim), [pk_val])
cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val])
# If it does already exist, do an UPDATE.
if cursor.fetchone():
if cursor.fetchone()[0] > 0:
db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks]
if db_values:
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \