Ticket #6940: orm-count-fix.patch
File orm-count-fix.patch, 1.1 KB (added by , 17 years ago) |
---|
-
django/db/models/query.py
231 231 232 232 try: 233 233 select, sql, params = counter._get_sql_clause() 234 235 formats_in_select = sum( [ 1 if s else -1 for s in ",".join( select ).split( "%" ) ] ) - 1 234 236 except EmptyResultSet: 235 237 return 0 236 238 … … 238 240 if self._distinct: 239 241 id_col = "%s.%s" % (connection.ops.quote_name(self.model._meta.db_table), 240 242 connection.ops.quote_name(self.model._meta.pk.column)) 241 cursor.execute("SELECT COUNT(DISTINCT(%s))" % id_col + sql, params )243 cursor.execute("SELECT COUNT(DISTINCT(%s))" % id_col + sql, params[formats_in_select:]) 242 244 else: 243 cursor.execute("SELECT COUNT(*)" + sql, params )245 cursor.execute("SELECT COUNT(*)" + sql, params[formats_in_select:]) 244 246 count = cursor.fetchone()[0] 245 247 246 248 # Apply any offset and limit constraints manually, since using LIMIT or