Ticket #1760: mysql_order_wrt_2.diff

File mysql_order_wrt_2.diff, 1.3 KB (added by James Turnbull <james@…>, 17 years ago)

Patch file for SVN version, removes MYSQL check and applies to correct lines

  • django/db/models/base.py

     
    228228            placeholders = ['%s'] * len(field_names)
    229229            if self._meta.order_with_respect_to:
    230230                field_names.append(backend.quote_name('_order'))
    231                 # TODO: This assumes the database supports subqueries.
    232                 placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \
    233                     (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.order_with_respect_to.column)))
    234                 db_values.append(getattr(self, self._meta.order_with_respect_to.attname))
     231                placeholders.append('%s')
     232                subsel = 'SELECT COUNT(*) FROM %s WHERE %s = %%s' % (
     233                    backend.quote_name(self._meta.db_table),
     234                    backend.quote_name(self._meta.order_with_respect_to.column))
     235                cursor.execute(subsel, (getattr(self, self._meta.order_with_respect_to.attname),))
     236                db_values.append(cursor.fetchone()[0])
    235237            if db_values:
    236238                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
    237239                    (backend.quote_name(self._meta.db_table), ','.join(field_names),
Back to Top