diff options
| author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 22:19:44 +0000 |
|---|---|---|
| committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 22:19:44 +0000 |
| commit | 39fd198ddd8d0e6915dc713eeac5fef6f40b74ed (patch) | |
| tree | ce04318b3af945567601f6c0efca03e0e8011f8a | |
| parent | e715476a9f128bffa8b82b840ac4e2ab69b2ad78 (diff) | |
[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
| -rw-r--r-- | django/db/models/base.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 71f800f4bf..1224e3f697 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -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" % \ |
