mirror of
https://github.com/django/django.git
synced 2025-08-31 15:57:45 +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:
parent
e7514e4978
commit
76aecfbc4b
7 changed files with 43 additions and 12 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue