mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #9055 -- Standardized behaviour of parameter escaping in db cursors
Previously, depending on the database backend or the cursor type, you'd need to double the percent signs in the query before passing it to cursor.execute. Now cursor.execute consistently need percent doubling whenever params argument is not None (placeholder substitution will happen). Thanks Thomas Güttler for the report and Walter Doekes for his work on the patch.
This commit is contained in:
@@ -361,18 +361,34 @@ class ConnectionCreatedSignalTest(TransactionTestCase):
|
||||
|
||||
|
||||
class EscapingChecks(TestCase):
|
||||
"""
|
||||
All tests in this test case are also run with settings.DEBUG=True in
|
||||
EscapingChecksDebug test case, to also test CursorDebugWrapper.
|
||||
"""
|
||||
def test_paramless_no_escaping(self):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT '%s'")
|
||||
self.assertEqual(cursor.fetchall()[0][0], '%s')
|
||||
|
||||
def test_parameter_escaping(self):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT '%%', %s", ('%d',))
|
||||
self.assertEqual(cursor.fetchall()[0], ('%', '%d'))
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'sqlite',
|
||||
"This is a sqlite-specific issue")
|
||||
def test_parameter_escaping(self):
|
||||
def test_sqlite_parameter_escaping(self):
|
||||
#13648: '%s' escaping support for sqlite3
|
||||
cursor = connection.cursor()
|
||||
response = cursor.execute(
|
||||
"select strftime('%%s', date('now'))").fetchall()[0][0]
|
||||
self.assertNotEqual(response, None)
|
||||
cursor.execute("select strftime('%s', date('now'))")
|
||||
response = cursor.fetchall()[0][0]
|
||||
# response should be an non-zero integer
|
||||
self.assertTrue(int(response))
|
||||
|
||||
@override_settings(DEBUG=True)
|
||||
class EscapingChecksDebug(EscapingChecks):
|
||||
pass
|
||||
|
||||
|
||||
class SqlliteAggregationTests(TestCase):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user