Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
freakboy3742 committed Feb 11, 2010
1 parent 4d2f489 commit ab828da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django/core/cache/backends/db.py
Expand Up @@ -12,7 +12,7 @@
class CacheClass(BaseCache): class CacheClass(BaseCache):
def __init__(self, table, params): def __init__(self, table, params):
BaseCache.__init__(self, params) BaseCache.__init__(self, params)
self._table = table self._table = connection.ops.quote_name(table)
max_entries = params.get('max_entries', 300) max_entries = params.get('max_entries', 300)
try: try:
self._max_entries = int(max_entries) self._max_entries = int(max_entries)
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/createcachetable.py
Expand Up @@ -38,8 +38,8 @@ def handle_label(self, tablename, **options):
field_output.append("UNIQUE") field_output.append("UNIQUE")
if f.db_index: if f.db_index:
unique = f.unique and "UNIQUE " or "" unique = f.unique and "UNIQUE " or ""
index_output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \ index_output.append("CREATE %sINDEX %s ON %s (%s);" % \
(unique, tablename, f.name, qn(tablename), (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename),
qn(f.name))) qn(f.name)))
table_output.append(" ".join(field_output)) table_output.append(" ".join(field_output))
full_statement = ["CREATE TABLE %s (" % qn(tablename)] full_statement = ["CREATE TABLE %s (" % qn(tablename)]
Expand Down
8 changes: 5 additions & 3 deletions tests/regressiontests/cache/tests.py
Expand Up @@ -342,13 +342,15 @@ def test_long_timeout(self):


class DBCacheTests(unittest.TestCase, BaseCacheTests): class DBCacheTests(unittest.TestCase, BaseCacheTests):
def setUp(self): def setUp(self):
management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False) # Spaces are used in the table name to ensure quoting/escaping is working
self.cache = get_cache('db://test_cache_table') 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): def tearDown(self):
from django.db import connection from django.db import connection
cursor = connection.cursor() 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): class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
def setUp(self): def setUp(self):
Expand Down

0 comments on commit ab828da

Please sign in to comment.