From ab828da2b91c71987ef23baee4a1613fdb330c5f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 11 Feb 2010 12:21:46 +0000 Subject: [PATCH] Fixed #11623 -- Corrected table name quoting in db cache backend. Thanks to Fraser Nevett for the report and fix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12410 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/cache/backends/db.py | 2 +- django/core/management/commands/createcachetable.py | 4 ++-- tests/regressiontests/cache/tests.py | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py index dd18cd6b1d..25cbe4d236 100644 --- a/django/core/cache/backends/db.py +++ b/django/core/cache/backends/db.py @@ -12,7 +12,7 @@ except ImportError: class CacheClass(BaseCache): def __init__(self, table, params): BaseCache.__init__(self, params) - self._table = table + self._table = connection.ops.quote_name(table) max_entries = params.get('max_entries', 300) try: self._max_entries = int(max_entries) diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py index c0d3cb8219..90172b6ca3 100644 --- a/django/core/management/commands/createcachetable.py +++ b/django/core/management/commands/createcachetable.py @@ -38,8 +38,8 @@ class Command(LabelCommand): field_output.append("UNIQUE") if f.db_index: unique = f.unique and "UNIQUE " or "" - index_output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \ - (unique, tablename, f.name, qn(tablename), + index_output.append("CREATE %sINDEX %s ON %s (%s);" % \ + (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename), qn(f.name))) table_output.append(" ".join(field_output)) full_statement = ["CREATE TABLE %s (" % qn(tablename)] diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 6ca4d8bce8..5d8d039cf5 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -342,13 +342,15 @@ class BaseCacheTests(object): class DBCacheTests(unittest.TestCase, BaseCacheTests): def setUp(self): - management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False) - self.cache = get_cache('db://test_cache_table') + # Spaces are used in the table name to ensure quoting/escaping is working + self._table_name = 'test cache table' + management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False) + self.cache = get_cache('db://%s' % self._table_name) def tearDown(self): from django.db import connection cursor = connection.cursor() - cursor.execute('DROP TABLE test_cache_table') + cursor.execute('DROP TABLE %s' % connection.ops.quote_name(self._table_name)) class LocMemCacheTests(unittest.TestCase, BaseCacheTests): def setUp(self):