diff -r d7a5c9caa5dd django/core/cache/backends/db.py
a
|
b
|
|
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() |
… |
… |
|
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 | cursor.execute("DELETE FROM %s" % self._table) |
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: |