diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 91dc4d2..c34481f 100644
a
|
b
|
class DatabaseOperations(BaseDatabaseOperations):
|
234 | 234 | # With MySQLdb, cursor objects have an (undocumented) "_last_executed" |
235 | 235 | # attribute where the exact query sent to the database is saved. |
236 | 236 | # See MySQLdb/cursors.py in the source distribution. |
237 | | return cursor._last_executed |
| 237 | return getattr(cursor, '_last_executed', None) |
238 | 238 | |
239 | 239 | def no_limit_value(self): |
240 | 240 | # 2**64 - 1, as recommended by the MySQL documentation |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 193d01b..988797a 100644
a
|
b
|
class DateQuotingTest(TestCase):
|
104 | 104 | |
105 | 105 | class LastExecutedQueryTest(TestCase): |
106 | 106 | |
107 | | def setUp(self): |
108 | | # connection.queries will not be filled in without this |
109 | | settings.DEBUG = True |
110 | | |
111 | | def tearDown(self): |
112 | | settings.DEBUG = False |
| 107 | def test_last_executed_query(self): |
| 108 | """ |
| 109 | last_executed_query should not raise an exception even if no previous |
| 110 | query has been run. |
| 111 | """ |
| 112 | cursor = connection.cursor() |
| 113 | try: |
| 114 | connection.ops.last_executed_query(cursor, '', ()) |
| 115 | except Exception: |
| 116 | self.fail("'last_executed_query' should not raise an exception.") |
113 | 117 | |
114 | 118 | # There are no tests for the sqlite backend because it does not |
115 | 119 | # implement paramater escaping. See #14091. |
116 | 120 | |
117 | 121 | @unittest.skipUnless(connection.vendor in ('oracle', 'postgresql'), |
118 | 122 | "These backends use the standard parameter escaping rules") |
| 123 | @override_settings(DEBUG=True) # so as connection.queries will be filled |
119 | 124 | def test_parameter_escaping(self): |
120 | 125 | # check that both numbers and string are properly quoted |
121 | 126 | list(models.Tag.objects.filter(name="special:\\\"':", object_id=12)) |
… |
… |
class LastExecutedQueryTest(TestCase):
|
125 | 130 | |
126 | 131 | @unittest.skipUnless(connection.vendor == 'mysql', |
127 | 132 | "MySQL uses backslashes to escape parameters.") |
| 133 | @override_settings(DEBUG=True) |
128 | 134 | def test_parameter_escaping(self): |
129 | 135 | list(models.Tag.objects.filter(name="special:\\\"':", object_id=12)) |
130 | 136 | sql = connection.queries[-1]['sql'] |