diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-03-23 16:09:56 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-03-23 17:11:10 +0100 |
| commit | 76aecfbc4b49f5ab0613cccff1df6fab03253fab (patch) | |
| tree | 288a5c0e14ebe27d051b0ec01d16977f76b99838 /tests | |
| parent | e7514e4978178ba68a872ac0004dd6f8049f3d76 (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index cec2267450..9a5f6c008d 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -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): """ |
