-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature for client side binding in schema_editor.
- Loading branch information
Showing
3 changed files
with
7 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,17 @@ | ||
from unittest import skipIf, skipUnless | ||
|
||
from django.db import connection | ||
from django.test import TestCase | ||
|
||
|
||
class SchemaLoggerTests(TestCase): | ||
@skipIf( | ||
connection.vendor == "postgresql", reason="postgresql will merge on the client" | ||
) | ||
def test_extra_args(self): | ||
editor = connection.schema_editor(collect_sql=True) | ||
sql = "SELECT * FROM foo WHERE id in (%s, %s)" | ||
params = [42, 1337] | ||
with self.assertLogs("django.db.backends.schema", "DEBUG") as cm: | ||
editor.execute(sql, params) | ||
if connection.features.schema_editor_uses_clientside_param_binding: | ||
sql = "SELECT * FROM foo WHERE id in (42, 1337)" | ||
params = None | ||
self.assertEqual(cm.records[0].sql, sql) | ||
self.assertEqual(cm.records[0].params, params) | ||
self.assertEqual( | ||
cm.records[0].getMessage(), | ||
"SELECT * FROM foo WHERE id in (%s, %s); (params [42, 1337])", | ||
) | ||
|
||
@skipUnless( | ||
connection.vendor == "postgresql", reason="postgres will merge on the client" | ||
) | ||
def test_extra_args_psycopg(self): | ||
editor = connection.schema_editor(collect_sql=True) | ||
sql = "SELECT * FROM foo WHERE id in (%s, %s)" | ||
params = [42, 1337] | ||
with self.assertLogs("django.db.backends.schema", "DEBUG") as cm: | ||
editor.execute(sql, params) | ||
merged = "SELECT * FROM foo WHERE id in (42, 1337)" | ||
self.assertEqual(cm.records[0].sql, merged) | ||
self.assertEqual(cm.records[0].params, None) | ||
self.assertEqual(cm.records[0].getMessage(), "%s; (params None)" % merged) | ||
self.assertEqual(cm.records[0].getMessage(), f"{sql}; (params {params})") |