mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #23426 -- Don't require double percent sign in RunSQL without parameters
This commit is contained in:
committed by
Tim Graham
parent
0aca91cf7f
commit
b9a670b227
@@ -1156,10 +1156,18 @@ class OperationTests(OperationTestBase):
|
||||
# Create the operation
|
||||
operation = migrations.RunSQL(
|
||||
# Use a multi-line string with a comment to test splitting on SQLite and MySQL respectively
|
||||
"CREATE TABLE i_love_ponies (id int, special_thing int);\n"
|
||||
"INSERT INTO i_love_ponies (id, special_thing) VALUES (1, 42); -- this is magic!\n"
|
||||
"INSERT INTO i_love_ponies (id, special_thing) VALUES (2, 51);\n",
|
||||
"CREATE TABLE i_love_ponies (id int, special_thing varchar(15));\n"
|
||||
"INSERT INTO i_love_ponies (id, special_thing) VALUES (1, 'i love ponies'); -- this is magic!\n"
|
||||
"INSERT INTO i_love_ponies (id, special_thing) VALUES (2, 'i love django');\n"
|
||||
"UPDATE i_love_ponies SET special_thing = 'Ponies' WHERE special_thing LIKE '%%ponies';"
|
||||
"UPDATE i_love_ponies SET special_thing = 'Django' WHERE special_thing LIKE '%django';",
|
||||
|
||||
# Run delete queries to test for parameter substitution failure
|
||||
# reported in #23426
|
||||
"DELETE FROM i_love_ponies WHERE special_thing LIKE '%Django%';"
|
||||
"DELETE FROM i_love_ponies WHERE special_thing LIKE '%%Ponies%%';"
|
||||
"DROP TABLE i_love_ponies",
|
||||
|
||||
state_operations=[migrations.CreateModel("SomethingElse", [("id", models.AutoField(primary_key=True))])],
|
||||
)
|
||||
self.assertEqual(operation.describe(), "Raw SQL operation")
|
||||
@@ -1177,6 +1185,10 @@ class OperationTests(OperationTestBase):
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SELECT COUNT(*) FROM i_love_ponies")
|
||||
self.assertEqual(cursor.fetchall()[0][0], 2)
|
||||
cursor.execute("SELECT COUNT(*) FROM i_love_ponies WHERE special_thing = 'Django'")
|
||||
self.assertEqual(cursor.fetchall()[0][0], 1)
|
||||
cursor.execute("SELECT COUNT(*) FROM i_love_ponies WHERE special_thing = 'Ponies'")
|
||||
self.assertEqual(cursor.fetchall()[0][0], 1)
|
||||
# And test reversal
|
||||
self.assertTrue(operation.reversible)
|
||||
with connection.schema_editor() as editor:
|
||||
|
||||
Reference in New Issue
Block a user