Fixed #2512 -- Fixed SQL error when saving existing empty models.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-08-10 03:55:03 +00:00
parent cba451c940
commit a6a402a7db
2 changed files with 8 additions and 5 deletions

View File

@ -176,11 +176,12 @@ class Model(object):
# If it does already exist, do an UPDATE. # If it does already exist, do an UPDATE.
if cursor.fetchone(): if cursor.fetchone():
db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks] db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks]
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \ if db_values:
(backend.quote_name(self._meta.db_table), cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]), (backend.quote_name(self._meta.db_table),
backend.quote_name(self._meta.pk.column)), ','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
db_values + [pk_val]) backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
else: else:
record_exists = False record_exists = False
if not pk_set or not record_exists: if not pk_set or not record_exists:

View File

@ -20,5 +20,7 @@ API_TESTS = """
2 2
>>> m.id is not None >>> m.id is not None
True True
>>> existing = Empty(m.id)
>>> existing.save()
""" """