From 5b0e4e49d4ab5e976fbfdde70c525a13220f3259 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 22 Apr 2011 12:14:54 +0000 Subject: Fixed #14091 - be more correct about logging queries in connection.queries. Thanks to Aymeric Augustin for figuring out how to make this work across multiple databases. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16081 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/backends/tests.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/regressiontests/backends/tests.py') diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index a6bac5a009..3191ef0c85 100644 --- a/tests/regressiontests/backends/tests.py +++ b/tests/regressiontests/backends/tests.py @@ -2,6 +2,7 @@ # Unit and doctests for specific database backends. import datetime +from django.conf import settings from django.core.management.color import no_style from django.db import backend, connection, connections, DEFAULT_DB_ALIAS, IntegrityError from django.db.backends.signals import connection_created @@ -85,6 +86,35 @@ class DateQuotingTest(TestCase): classes = models.SchoolClass.objects.filter(last_updated__day=20) self.assertEqual(len(classes), 1) +class LastExecutedQueryTest(TestCase): + + def setUp(self): + # connection.queries will not be filled in without this + settings.DEBUG = True + + def tearDown(self): + settings.DEBUG = False + + # There are no tests for the sqlite backend because it does not + # implement paramater escaping. See #14091. + + @unittest.skipUnless(connection.vendor in ('oracle', 'postgresql'), + "These backends use the standard parameter escaping rules") + def test_parameter_escaping(self): + # check that both numbers and string are properly quoted + list(models.Tag.objects.filter(name="special:\\\"':", object_id=12)) + sql = connection.queries[-1]['sql'] + self.assertTrue("= 'special:\\\"'':' " in sql) + self.assertTrue("= 12 " in sql) + + @unittest.skipUnless(connection.vendor == 'mysql', + "MySQL uses backslashes to escape parameters.") + def test_parameter_escaping(self): + list(models.Tag.objects.filter(name="special:\\\"':", object_id=12)) + sql = connection.queries[-1]['sql'] + # only this line is different from the test above + self.assertTrue("= 'special:\\\\\\\"\\':' " in sql) + self.assertTrue("= 12 " in sql) class ParameterHandlingTest(TestCase): def test_bad_parameter_count(self): -- cgit v1.3