Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11623 -- Corrected table name quoting in db cache back…

…end. Thanks to Fraser Nevett for the report and fix.

Backport of r12410 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12414 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d4a34b5508a73c47d9e7220ee92dd7b8fb9e4262 1 parent a928216
Russell Keith-Magee authored February 11, 2010
2  django/core/cache/backends/db.py
@@ -12,7 +12,7 @@
12 12
 class CacheClass(BaseCache):
13 13
     def __init__(self, table, params):
14 14
         BaseCache.__init__(self, params)
15  
-        self._table = table
  15
+        self._table = connection.ops.quote_name(table)
16 16
         max_entries = params.get('max_entries', 300)
17 17
         try:
18 18
             self._max_entries = int(max_entries)
4  django/core/management/commands/createcachetable.py
@@ -27,8 +27,8 @@ def handle_label(self, tablename, **options):
27 27
                 field_output.append("UNIQUE")
28 28
             if f.db_index:
29 29
                 unique = f.unique and "UNIQUE " or ""
30  
-                index_output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \
31  
-                    (unique, tablename, f.name, qn(tablename),
  30
+                index_output.append("CREATE %sINDEX %s ON %s (%s);" % \
  31
+                    (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename),
32 32
                     qn(f.name)))
33 33
             table_output.append(" ".join(field_output))
34 34
         full_statement = ["CREATE TABLE %s (" % qn(tablename)]
8  tests/regressiontests/cache/tests.py
@@ -296,13 +296,15 @@ def test_long_timeout(self):
296 296
 
297 297
 class DBCacheTests(unittest.TestCase, BaseCacheTests):
298 298
     def setUp(self):
299  
-        management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False)
300  
-        self.cache = get_cache('db://test_cache_table')
  299
+        # Spaces are used in the table name to ensure quoting/escaping is working
  300
+        self._table_name = 'test cache table'
  301
+        management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False)
  302
+        self.cache = get_cache('db://%s' % self._table_name)
301 303
 
302 304
     def tearDown(self):
303 305
         from django.db import connection
304 306
         cursor = connection.cursor()
305  
-        cursor.execute('DROP TABLE test_cache_table');
  307
+        cursor.execute('DROP TABLE %s' % connection.ops.quote_name(self._table_name))
306 308
 
307 309
 class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
308 310
     def setUp(self):

0 notes on commit d4a34b5

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