Ticket #11623: db-cache-quoting.diff

File db-cache-quoting.diff, 2.5 KB (added by Fraser Nevett, 15 years ago)

Patch and tests

  • django/core/cache/backends/db.py

     
    1212class CacheClass(BaseCache):
    1313    def __init__(self, table, params):
    1414        BaseCache.__init__(self, params)
    15         self._table = table
     15        self._table = connection.ops.quote_name(table)
    1616        max_entries = params.get('max_entries', 300)
    1717        try:
    1818            self._max_entries = int(max_entries)
  • django/core/management/commands/createcachetable.py

     
    2727                field_output.append("UNIQUE")
    2828            if f.db_index:
    2929                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),
    3232                    qn(f.name)))
    3333            table_output.append(" ".join(field_output))
    3434        full_statement = ["CREATE TABLE %s (" % qn(tablename)]
  • tests/regressiontests/cache/tests.py

     
    238238
    239239class DBCacheTests(unittest.TestCase, BaseCacheTests):
    240240    def setUp(self):
    241         management.call_command('createcachetable', 'test_cache_table', verbosity=0, interactive=False)
    242         self.cache = get_cache('db://test_cache_table')
     241        # Spaces are used in the table name to ensure quoting/escaping is working
     242        self._table_name = 'test cache table'
     243        management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False)
     244        self.cache = get_cache('db://%s' % self._table_name)
    243245
    244246    def tearDown(self):
    245247        from django.db import connection
    246248        cursor = connection.cursor()
    247         cursor.execute('DROP TABLE test_cache_table');
     249        cursor.execute('DROP TABLE %s' % connection.ops.quote_name(self._table_name));
    248250
    249251class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
    250252    def setUp(self):
Back to Top