diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 78dbbc6..7dc5456 100644
|
a
|
b
|
class BaseDatabaseOperations(object):
|
| 614 | 614 | # Convert params to contain Unicode values. |
| 615 | 615 | to_unicode = lambda s: force_text(s, strings_only=True, errors='replace') |
| 616 | 616 | if isinstance(params, (list, tuple)): |
| 617 | | u_params = tuple([to_unicode(val) for val in params]) |
| | 617 | u_params = tuple(to_unicode(val) for val in params) |
| 618 | 618 | else: |
| 619 | | u_params = dict([(to_unicode(k), to_unicode(v)) for k, v in params.items()]) |
| | 619 | u_params = dict((to_unicode(k), to_unicode(v)) for k, v in params.items()) |
| 620 | 620 | |
| 621 | | return force_text(sql) % u_params |
| | 621 | return six.text_type("QUERY = %r - PARAMS = %r") % (sql, u_params) |
| 622 | 622 | |
| 623 | 623 | def last_insert_id(self, cursor, table_name, pk_name): |
| 624 | 624 | """ |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index b293847..313fdc8 100644
|
a
|
b
|
from django.db.models import fields, Sum, Avg, Variance, StdDev
|
| 16 | 16 | from django.db.utils import ConnectionHandler, DatabaseError, load_backend |
| 17 | 17 | from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature, |
| 18 | 18 | TransactionTestCase) |
| 19 | | from django.test.utils import override_settings |
| | 19 | from django.test.utils import override_settings, str_prefix |
| 20 | 20 | from django.utils import six |
| 21 | 21 | from django.utils.six.moves import xrange |
| 22 | 22 | from django.utils import unittest |
| … |
… |
class DateQuotingTest(TestCase):
|
| 160 | 160 | self.assertEqual(len(classes), 1) |
| 161 | 161 | |
| 162 | 162 | |
| | 163 | @override_settings(DEBUG=True) |
| 163 | 164 | class LastExecutedQueryTest(TestCase): |
| 164 | | @override_settings(DEBUG=True) |
| | 165 | |
| 165 | 166 | def test_debug_sql(self): |
| 166 | 167 | list(models.Tag.objects.filter(name="test")) |
| 167 | 168 | sql = connection.queries[-1]['sql'].lower() |
| 168 | | self.assertTrue(sql.startswith("select")) |
| | 169 | self.assertIn("select", sql) |
| 169 | 170 | self.assertIn(models.Tag._meta.db_table, sql) |
| 170 | 171 | |
| 171 | 172 | def test_query_encoding(self): |
| 172 | 173 | """ |
| 173 | 174 | Test that last_executed_query() returns an Unicode string |
| 174 | 175 | """ |
| 175 | | tags = models.Tag.objects.extra(select={'föö':1}) |
| | 176 | tags = models.Tag.objects.extra(select={'föö': 1}) |
| 176 | 177 | sql, params = tags.query.sql_with_params() |
| 177 | 178 | cursor = tags.query.get_compiler('default').execute_sql(None) |
| 178 | 179 | last_sql = cursor.db.ops.last_executed_query(cursor, sql, params) |
| 179 | 180 | self.assertTrue(isinstance(last_sql, six.text_type)) |
| 180 | 181 | |
| | 182 | @unittest.skipUnless(connection.vendor == 'sqlite', |
| | 183 | "This test is specific to SQLite.") |
| | 184 | def test_no_interpolation_on_sqlite(self): |
| | 185 | # Regression for #17158 |
| | 186 | # This shouldn't raise an exception |
| | 187 | query = "SELECT strftime('%Y', 'now');" |
| | 188 | connection.cursor().execute(query) |
| | 189 | self.assertEqual(connection.queries[-1]['sql'], |
| | 190 | str_prefix("QUERY = %(_)s\"SELECT strftime('%%Y', 'now');\" - PARAMS = ()")) |
| 181 | 191 | |
| 182 | 192 | class ParameterHandlingTest(TestCase): |
| 183 | 193 | def test_bad_parameter_count(self): |