mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
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
This commit is contained in:
parent
598032b8c4
commit
5b0e4e49d4
7 changed files with 57 additions and 7 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue