summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2011-04-22 12:14:54 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2011-04-22 12:14:54 +0000
commit5b0e4e49d4ab5e976fbfdde70c525a13220f3259 (patch)
tree5e09c9c9eedefb8b0d815c0214afc09b4db76653 /tests
parent598032b8c4ec7d642b6223af8569bef81d183385 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/backends/tests.py30
1 files changed, 30 insertions, 0 deletions
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):