Ticket #33340: 33340.diff

File 33340.diff, 2.7 KB (added by Tim Graham, 2 years ago)
  • django/core/cache/backends/db.py

    diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py
    index acbe702255..ec616d7e31 100644
    a b class DatabaseCache(BaseDatabaseCache):  
    243243
    244244        with connection.cursor() as cursor:
    245245            cursor.execute(
    246                 'SELECT %s FROM %s WHERE %s = %%s and expires > %%s' % (
     246                'SELECT %s FROM %s WHERE %s = %%s and %s > %%s' % (
    247247                    quote_name('cache_key'),
    248248                    quote_name(self._table),
    249249                    quote_name('cache_key'),
     250                    quote_name('expires'),
    250251                ),
    251252                [key, connection.ops.adapt_datetimefield_value(now)]
    252253            )
    class DatabaseCache(BaseDatabaseCache):  
    257258            self.clear()
    258259        else:
    259260            connection = connections[db]
    260             table = connection.ops.quote_name(self._table)
    261             cursor.execute("DELETE FROM %s WHERE expires < %%s" % table,
    262                            [connection.ops.adapt_datetimefield_value(now)])
     261            quote_name = connection.ops.quote_name
     262            table = quote_name(self._table)
     263            cursor.execute(
     264                'DELETE FROM %s WHERE %s < %%s' % (
     265                    table,
     266                    quote_name('expires'),
     267                ),
     268                [connection.ops.adapt_datetimefield_value(now)]
     269            )
    263270            cursor.execute("SELECT COUNT(*) FROM %s" % table)
    264271            num = cursor.fetchone()[0]
    265272            if num > self._max_entries:
    class DatabaseCache(BaseDatabaseCache):  
    270277                last_cache_key = cursor.fetchone()
    271278                if last_cache_key:
    272279                    cursor.execute(
    273                         'DELETE FROM %s WHERE cache_key < %%s' % table,
     280                        'DELETE FROM %s WHERE %s < %%s' % (
     281                            table,
     282                            quote_name('cache_key'),
     283                        ),
    274284                        [last_cache_key[0]],
    275285                    )
    276286
  • django/db/backends/base/operations.py

    diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
    index 0fcc607bcf..d7a4472483 100644
    a b class BaseDatabaseOperations:  
    8282        This is used by the 'db' cache backend to determine where to start
    8383        culling.
    8484        """
    85         return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
     85        cache_key = self.ops.quote_name('cache_key')
     86        return f"SELECT {cache_key} FROM %s ORDER BY {cache_key} LIMIT 1 OFFSET %%s"
    8687
    8788    def unification_cast_sql(self, output_field):
    8889        """
Back to Top