Django

Code

Changeset 5882

Show
Ignore:
Timestamp:
08/13/07 16:42:37 (1 year ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/base.py

    r5658 r5882  
    214214        if pk_set: 
    215215            # Determine whether a record with the primary key already exists. 
    216             cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \ 
     216            cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \ 
    217217                (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), 
    218218                self._meta.pk.get_db_prep_lookup('exact', pk_val)) 
    219219            # If it does already exist, do an UPDATE. 
    220             if cursor.fetchone()[0] > 0
     220            if cursor.fetchone()
    221221                db_values = [f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False)) for f in non_pks] 
    222222                if db_values: