summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-08-21 17:19:35 +0000
committerRamiro Morales <cramm0@gmail.com>2011-08-21 17:19:35 +0000
commit2d51abfeb5abd64d970f17657e8e992495eac851 (patch)
tree21143c8b3f4af17ef1b5a3aff54998ce33b6e045
parentcdd44dca454f7b2b347316e8faadd32f3684faa7 (diff)
Fixed #16481 -- Adapted one raw SQL query in cull immplementation of 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
-rw-r--r--django/core/cache/backends/db.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py
index fb05851e4b..af343ffc5d 100644
--- a/django/core/cache/backends/db.py
+++ b/django/core/cache/backends/db.py
@@ -135,7 +135,13 @@ class DatabaseCache(BaseDatabaseCache):
cursor.execute("SELECT COUNT(*) FROM %s" % table)
num = cursor.fetchone()[0]
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]])
def clear(self):