Kaydet (Commit) a6a402a7 authored tarafından Malcolm Tredinnick's avatar Malcolm Tredinnick

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
üst cba451c9
......@@ -176,11 +176,12 @@ class Model(object):
# If it does already exist, do an UPDATE.
if cursor.fetchone():
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" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
if db_values:
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
else:
record_exists = False
if not pk_set or not record_exists:
......
......@@ -20,5 +20,7 @@ API_TESTS = """
2
>>> m.id is not None
True
>>> existing = Empty(m.id)
>>> existing.save()
"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment