Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1760 -- Unwound a subselect in an update for order_with_respec…

…t_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
  • Loading branch information...
commit 595bf6b691c8ee3738d84f5cf15670ec6c3a01a6 1 parent b7df720
Malcolm Tredinnick authored September 14, 2007

Showing 1 changed file with 6 additions and 4 deletions. Show diff stats Hide diff stats

  1. 10  django/db/models/base.py
10  django/db/models/base.py
@@ -241,10 +241,12 @@ def save(self, raw=False):
241 241
             placeholders = ['%s'] * len(field_names)
242 242
             if self._meta.order_with_respect_to:
243 243
                 field_names.append(qn('_order'))
244  
-                # TODO: This assumes the database supports subqueries.
245  
-                placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \
246  
-                    (qn(self._meta.db_table), qn(self._meta.order_with_respect_to.column)))
247  
-                db_values.append(getattr(self, self._meta.order_with_respect_to.attname))
  244
+                placeholders.append('%s')
  245
+                subsel = 'SELECT COUNT(*) FROM %s WHERE %s = %%s' % (
  246
+                    qn(self._meta.db_table),
  247
+                    qn(self._meta.order_with_respect_to.column))
  248
+                cursor.execute(subsel, (getattr(self, self._meta.order_with_respect_to.attname),))
  249
+                db_values.append(cursor.fetchone()[0])
248 250
             if db_values:
249 251
                 cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
250 252
                     (qn(self._meta.db_table), ','.join(field_names),

0 notes on commit 595bf6b

Please sign in to comment.
Something went wrong with that request. Please try again.