diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-14 13:56:36 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-14 13:56:36 +0000 |
| commit | 595bf6b691c8ee3738d84f5cf15670ec6c3a01a6 (patch) | |
| tree | d53dabcd6ed8a0329804d6d076e6fde31dfee06b | |
| parent | b7df72083958122194740fdb5a9f7d4714114e37 (diff) | |
Fixed #1760 -- Unwound a subselect in an update for order_with_respect_to handling. Required for MySQL and doesn't hurt too much for other platforms. thanks, Christopher Lenz, James Turnbull and Simon Litchfield.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6187 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/base.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index a3478445f7..b7d6e93def 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -241,10 +241,12 @@ class Model(object): placeholders = ['%s'] * len(field_names) if self._meta.order_with_respect_to: field_names.append(qn('_order')) - # TODO: This assumes the database supports subqueries. - placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \ - (qn(self._meta.db_table), qn(self._meta.order_with_respect_to.column))) - db_values.append(getattr(self, self._meta.order_with_respect_to.attname)) + placeholders.append('%s') + subsel = 'SELECT COUNT(*) FROM %s WHERE %s = %%s' % ( + qn(self._meta.db_table), + qn(self._meta.order_with_respect_to.column)) + cursor.execute(subsel, (getattr(self, self._meta.order_with_respect_to.attname),)) + db_values.append(cursor.fetchone()[0]) if db_values: cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ (qn(self._meta.db_table), ','.join(field_names), |
