Ticket #9055: 9055-2.diff

File 9055-2.diff, 3.3 KB (added by Claude Paroz, 12 years ago)

Patch including tests for MySQL and SQLite

  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index ebe8875..3af6f1f 100644
    a b class BaseDatabaseOperations(object):  
    589589        to_unicode = lambda s: force_unicode(s, strings_only=True, errors='replace')
    590590        if isinstance(params, (list, tuple)):
    591591            u_params = tuple([to_unicode(val) for val in params])
     592        elif params is None:
     593            u_params = ()
    592594        else:
    593595            u_params = dict([(to_unicode(k), to_unicode(v)) for k, v in params.items()])
    594596
  • django/db/backends/util.py

    diff --git a/django/db/backends/util.py b/django/db/backends/util.py
    index b0463b7..ec949eb 100644
    a b class CursorWrapper(object):  
    3030
    3131class CursorDebugWrapper(CursorWrapper):
    3232
    33     def execute(self, sql, params=()):
     33    def execute(self, sql, params=None):
    3434        start = time()
    3535        try:
    36             return self.cursor.execute(sql, params)
     36            if params is None:
     37                # params default might be backend specific
     38                return self.cursor.execute(sql)
     39            else:
     40                return self.cursor.execute(sql, params)
    3741        finally:
    3842            stop = time()
    3943            duration = stop - start
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index 436da8c..5ff2c60 100644
    a b from django.db.backends.signals import connection_created  
    1414from django.db.backends.postgresql_psycopg2 import version as pg_version
    1515from django.db.utils import ConnectionHandler, DatabaseError, load_backend
    1616from django.test import TestCase, skipUnlessDBFeature, TransactionTestCase
     17from django.test.utils import override_settings
    1718from django.utils import unittest
    1819
    1920from . import models
    class ConnectionCreatedSignalTest(TestCase):  
    294295
    295296
    296297class EscapingChecks(TestCase):
    297 
     298    """ Each test is run once with normal cursor, and once with
     299        CursorDebugWrapper activated by setting DEBUG to True
     300    """
    298301    @unittest.skipUnless(connection.vendor == 'sqlite',
    299302                         "This is a sqlite-specific issue")
    300303    def test_parameter_escaping(self):
    class EscapingChecks(TestCase):  
    306309        # response should be an non-zero integer
    307310        self.assertTrue(int(response))
    308311
     312    @unittest.skipUnless(connection.vendor == 'sqlite',
     313                         "This is a sqlite-specific issue")
     314    @override_settings(DEBUG=True)
     315    def test_parameter_escaping_debug(self):
     316        self.test_parameter_escaping()
     317
     318    @unittest.skipUnless(connection.vendor == 'mysql',
     319                         "This is a mysql-specific test")
     320    def test_parameter_escaping_mysql(self):
     321        cursor = connection.cursor()
     322        response = cursor.execute("SELECT DATE_FORMAT(NOW(), '%%Y-%%m-%%e')")
     323        self.assertTrue(len(cursor.fetchall()[0][0]) > 6)
     324
     325    @unittest.skipUnless(connection.vendor == 'mysql',
     326                         "This is a mysql-specific test")
     327    @override_settings(DEBUG=True)
     328    def test_parameter_escaping_mysql_debug(self):
     329        self.test_parameter_escaping_mysql()
     330
    309331
    310332class BackendTestCase(TestCase):
    311333    def test_cursor_executemany(self):
Back to Top