Changeset 5531 for django/branches/unicode/django/db/models/base.py
- Timestamp:
- 06/25/07 07:47:19 (2 years ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/django/db/models/base.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode
- Property svnmerge-integrated changed from /django/trunk:1-5460 to /django/trunk:1-5530
django/branches/unicode/django/db/models/base.py
r5400 r5531 100 100 def __init__(self, *args, **kwargs): 101 101 dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs) 102 102 103 103 # There is a rather weird disparity here; if kwargs, it's set, then args 104 # overrides it. It should be one or the other; don't duplicate the work 104 # overrides it. It should be one or the other; don't duplicate the work 105 105 # The reason for the kwargs check is that standard iterator passes in by 106 106 # args, and nstantiation for iteration is 33% faster. … … 126 126 if isinstance(field.rel, ManyToOneRel): 127 127 kwargs.pop(field.attname, None) 128 128 129 129 # Now we're left with the unprocessed fields that *must* come from 130 130 # keywords, or default. 131 131 132 132 for field in fields_iter: 133 133 if kwargs: … … 151 151 val = getattr(rel_obj, field.rel.get_related_field().attname) 152 152 except AttributeError: 153 raise TypeError("Invalid value: %r should be a %s instance, not a %s" % 153 raise TypeError("Invalid value: %r should be a %s instance, not a %s" % 154 154 (field.name, field.rel.to, type(rel_obj))) 155 155 else: … … 214 214 if pk_set: 215 215 # Determine whether a record with the primary key already exists. 216 cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \ 217 (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val]) 216 cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \ 217 (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), 218 self._meta.pk.get_db_prep_lookup('exact', pk_val)) 218 219 # If it does already exist, do an UPDATE. 219 if cursor.fetchone() :220 if cursor.fetchone()[0] > 0: 220 221 db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks] 221 222 if db_values: … … 224 225 ','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]), 225 226 backend.quote_name(self._meta.pk.column)), 226 db_values + [pk_val])227 db_values + self._meta.pk.get_db_prep_lookup('exact', pk_val)) 227 228 else: 228 229 record_exists = False
