Ticket #16481: 16481.patch

File 16481.patch, 1.3 KB (added by Aymeric Augustin, 13 years ago)
  • django/core/cache/backends/db.py

     
    135135            cursor.execute("SELECT COUNT(*) FROM %s" % table)
    136136            num = cursor.fetchone()[0]
    137137            if num > self._max_entries:
    138                 cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency])
     138                cull_num = num / self._cull_frequency
     139                if connections[db].vendor == 'oracle':
     140                    # Special case for Oracle because it doesn't support LIMIT + OFFSET
     141                    cursor.execute("SELECT cache_key FROM (SELECT ROW_NUMBER() OVER (ORDER BY cache_key) AS counter, cache_key FROM %s) WHERE counter > %%s AND COUNTER <= %%s" % table, [cull_num, cull_num + 1])
     142                else:
     143                    # This isn't standard SQL, it's likely to break with some non officially supported databases             
     144                    cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [cull_num])
    139145                cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]])
    140146
    141147    def clear(self):
Back to Top