summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/core/cache/backends/db.py14
-rw-r--r--django/db/backends/base/operations.py3
-rw-r--r--django/db/backends/oracle/operations.py7
3 files changed, 18 insertions, 6 deletions
diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py
index ef95b1dd16..5bb1c5aec5 100644
--- a/django/core/cache/backends/db.py
+++ b/django/core/cache/backends/db.py
@@ -228,10 +228,11 @@ class DatabaseCache(BaseDatabaseCache):
with connection.cursor() as cursor:
cursor.execute(
- 'SELECT %s FROM %s WHERE %s = %%s and expires > %%s' % (
+ 'SELECT %s FROM %s WHERE %s = %%s and %s > %%s' % (
quote_name('cache_key'),
quote_name(self._table),
quote_name('cache_key'),
+ quote_name('expires'),
),
[key, connection.ops.adapt_datetimefield_value(now)]
)
@@ -243,8 +244,10 @@ class DatabaseCache(BaseDatabaseCache):
else:
connection = connections[db]
table = connection.ops.quote_name(self._table)
- cursor.execute("DELETE FROM %s WHERE expires < %%s" % table,
- [connection.ops.adapt_datetimefield_value(now)])
+ cursor.execute('DELETE FROM %s WHERE %s < %%s' % (
+ table,
+ connection.ops.quote_name('expires'),
+ ), [connection.ops.adapt_datetimefield_value(now)])
deleted_count = cursor.rowcount
remaining_num = num - deleted_count
if remaining_num > self._max_entries:
@@ -255,7 +258,10 @@ class DatabaseCache(BaseDatabaseCache):
last_cache_key = cursor.fetchone()
if last_cache_key:
cursor.execute(
- 'DELETE FROM %s WHERE cache_key < %%s' % table,
+ 'DELETE FROM %s WHERE %s < %%s' % (
+ table,
+ connection.ops.quote_name('cache_key'),
+ ),
[last_cache_key[0]],
)
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index 27fe486e2f..66bb009175 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -88,7 +88,8 @@ class BaseDatabaseOperations:
This is used by the 'db' cache backend to determine where to start
culling.
"""
- return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
+ cache_key = self.quote_name('cache_key')
+ return f'SELECT {cache_key} FROM %s ORDER BY {cache_key} LIMIT 1 OFFSET %%s'
def unification_cast_sql(self, output_field):
"""
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index f497390bea..c357c75351 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -72,7 +72,12 @@ END;
}
def cache_key_culling_sql(self):
- return 'SELECT cache_key FROM %s ORDER BY cache_key OFFSET %%s ROWS FETCH FIRST 1 ROWS ONLY'
+ cache_key = self.quote_name('cache_key')
+ return (
+ f'SELECT {cache_key} '
+ f'FROM %s '
+ f'ORDER BY {cache_key} OFFSET %%s ROWS FETCH FIRST 1 ROWS ONLY'
+ )
def date_extract_sql(self, lookup_type, field_name):
if lookup_type == 'week_day':