Django

Code

Changeset 6187

Show
Ignore:
Timestamp:
09/14/07 08:56:36 (1 year ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/base.py

    r5975 r6187  
    242242            if self._meta.order_with_respect_to: 
    243243                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]) 
    248250            if db_values: 
    249251                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \