Skip to content

Commit

Permalink
Fixed #16481 -- Adapted one raw SQL query in cull immplementation of …
Browse files Browse the repository at this point in the history
…the database-based cache backend so it works with Oracle. Thanks Aymeric Augustin for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16635 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ramiro committed Aug 21, 2011
1 parent cdd44dc commit 2d51abf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django/core/cache/backends/db.py
Expand Up @@ -135,7 +135,13 @@ def _cull(self, db, cursor, now):
cursor.execute("SELECT COUNT(*) FROM %s" % table) cursor.execute("SELECT COUNT(*) FROM %s" % table)
num = cursor.fetchone()[0] num = cursor.fetchone()[0]
if num > self._max_entries: if num > self._max_entries:
cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency]) cull_num = num / self._cull_frequency
if connections[db].vendor == 'oracle':
# Special case for Oracle because it doesn't support LIMIT + OFFSET
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])
else:
# This isn't standard SQL, it's likely to break with some non officially supported databases
cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [cull_num])
cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]])


def clear(self): def clear(self):
Expand Down

0 comments on commit 2d51abf

Please sign in to comment.