Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11483 -- Modified db cache backend to use db backend functions…

… for date conversion, avoiding problems under Jython. Thanks to Leo Soto for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12411 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 02d40b93f826558c5ed299e502812ac88b7ede12 1 parent ab828da
Russell Keith-Magee authored February 11, 2010

Showing 1 changed file with 8 additions and 4 deletions. Show diff stats Hide diff stats

  1. 12  django/core/cache/backends/db.py
12  django/core/cache/backends/db.py
@@ -60,9 +60,11 @@ def _base_set(self, mode, key, value, timeout=None):
60 60
             result = cursor.fetchone()
61 61
             if result and (mode == 'set' or
62 62
                     (mode == 'add' and result[1] < now)):
63  
-                cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table, [encoded, str(exp), key])
  63
+                cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % self._table,
  64
+                               [encoded, connection.ops.value_to_db_datetime(exp), key])
64 65
             else:
65  
-                cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table, [key, encoded, str(exp)])
  66
+                cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % self._table,
  67
+                               [key, encoded, connection.ops.value_to_db_datetime(exp)])
66 68
         except DatabaseError:
67 69
             # To be threadsafe, updates/inserts are allowed to fail silently
68 70
             transaction.rollback_unless_managed()
@@ -79,14 +81,16 @@ def delete(self, key):
79 81
     def has_key(self, key):
80 82
         now = datetime.now().replace(microsecond=0)
81 83
         cursor = connection.cursor()
82  
-        cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table, [key, now])
  84
+        cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % self._table,
  85
+                       [key, connection.ops.value_to_db_datetime(now)])
83 86
         return cursor.fetchone() is not None
84 87
 
85 88
     def _cull(self, cursor, now):
86 89
         if self._cull_frequency == 0:
87 90
             self.clear()
88 91
         else:
89  
-            cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table, [str(now)])
  92
+            cursor.execute("DELETE FROM %s WHERE expires < %%s" % self._table,
  93
+                           [connection.ops.value_to_db_datetime(now)])
90 94
             cursor.execute("SELECT COUNT(*) FROM %s" % self._table)
91 95
             num = cursor.fetchone()[0]
92 96
             if num > self._max_entries:

0 notes on commit 02d40b9

Please sign in to comment.
Something went wrong with that request. Please try again.