mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Refs #20010 -- Unified DatabaseOperations.last_executed_query() on Oracle with other db backends.
Thanks Simon Charette for the review.
This commit is contained in:
parent
6b4e57d79f
commit
79065b55a7
2 changed files with 42 additions and 5 deletions
|
@ -51,7 +51,7 @@ class DateQuotingTest(TestCase):
|
|||
@override_settings(DEBUG=True)
|
||||
class LastExecutedQueryTest(TestCase):
|
||||
|
||||
def test_last_executed_query(self):
|
||||
def test_last_executed_query_without_previous_query(self):
|
||||
"""
|
||||
last_executed_query should not raise an exception even if no previous
|
||||
query has been run.
|
||||
|
@ -73,6 +73,36 @@ class LastExecutedQueryTest(TestCase):
|
|||
last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
|
||||
self.assertIsInstance(last_sql, str)
|
||||
|
||||
def test_last_executed_query(self):
|
||||
# last_executed_query() interpolate all parameters, in most cases it is
|
||||
# not equal to QuerySet.query.
|
||||
for qs in (
|
||||
Article.objects.filter(pk=1),
|
||||
Article.objects.filter(pk__in=(1, 2), reporter__pk=3),
|
||||
):
|
||||
sql, params = qs.query.sql_with_params()
|
||||
cursor = qs.query.get_compiler(DEFAULT_DB_ALIAS).execute_sql(CURSOR)
|
||||
self.assertEqual(
|
||||
cursor.db.ops.last_executed_query(cursor, sql, params),
|
||||
str(qs.query),
|
||||
)
|
||||
|
||||
@skipUnlessDBFeature('supports_paramstyle_pyformat')
|
||||
def test_last_executed_query_dict(self):
|
||||
square_opts = Square._meta
|
||||
sql = 'INSERT INTO %s (%s, %s) VALUES (%%(root)s, %%(square)s)' % (
|
||||
connection.introspection.identifier_converter(square_opts.db_table),
|
||||
connection.ops.quote_name(square_opts.get_field('root').column),
|
||||
connection.ops.quote_name(square_opts.get_field('square').column),
|
||||
)
|
||||
with connection.cursor() as cursor:
|
||||
params = {'root': 2, 'square': 4}
|
||||
cursor.execute(sql, params)
|
||||
self.assertEqual(
|
||||
cursor.db.ops.last_executed_query(cursor, sql, params),
|
||||
sql % params,
|
||||
)
|
||||
|
||||
|
||||
class ParameterHandlingTest(TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue