Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11623 -- Corrected table name quoting in db cache backend. Tha…

…nks to Fraser Nevett for the report and fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12410 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ab828da2b91c71987ef23baee4a1613fdb330c5f 1 parent 4d2f489
Russell Keith-Magee authored
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
@@ -38,8 +38,8 @@ def handle_label(self, tablename, **options):
38 38
                 field_output.append("UNIQUE")
39 39
             if f.db_index:
40 40
                 unique = f.unique and "UNIQUE " or ""
41  
-                index_output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \
42  
-                    (unique, tablename, f.name, qn(tablename),
  41
+                index_output.append("CREATE %sINDEX %s ON %s (%s);" % \
  42
+                    (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename),
43 43
                     qn(f.name)))
44 44
             table_output.append(" ".join(field_output))
45 45
         full_statement = ["CREATE TABLE %s (" % qn(tablename)]
8  tests/regressiontests/cache/tests.py
@@ -342,13 +342,15 @@ def test_long_timeout(self):
342 342
 
343 343
 class DBCacheTests(unittest.TestCase, BaseCacheTests):
344 344
     def setUp(self):
345  
-        management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False)
346  
-        self.cache = get_cache('db://test_cache_table')
  345
+        # Spaces are used in the table name to ensure quoting/escaping is working
  346
+        self._table_name = 'test cache table'
  347
+        management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False)
  348
+        self.cache = get_cache('db://%s' % self._table_name)
347 349
 
348 350
     def tearDown(self):
349 351
         from django.db import connection
350 352
         cursor = connection.cursor()
351  
-        cursor.execute('DROP TABLE test_cache_table')
  353
+        cursor.execute('DROP TABLE %s' % connection.ops.quote_name(self._table_name))
352 354
 
353 355
 class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
354 356
     def setUp(self):

0 notes on commit ab828da

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