Author: mtredinnick
Date: 2007-09-14 08:56:36 -0500 (Fri, 14 Sep 2007)
New Revision: 6187
Modified:
django/trunk/django/db/models/base.py
Log:
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.
Modified: django/trunk/django/db/models/base.py
===================================================================
--- django/trunk/django/db/models/base.py 2007-09-14 12:48:10 UTC (rev
6186)
+++ django/trunk/django/db/models/base.py 2007-09-14 13:56:36 UTC (rev
6187)
@@ -241,10 +241,12 @@
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),
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---