summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <simon.charette@zapier.com>2019-04-29 22:49:45 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-04-30 08:54:30 +0200
commitf36239fa190c77883d4c09ad18da63278c1a6cf4 (patch)
treedb7c91d53244bdffe37a49036022ba4e448b3ac6 /django
parentd326c743ef2052faf1490f59afbc3e7bcf023c69 (diff)
[2.2.x] Fixed #30408 -- Fixed crash when adding check constraints with LIKE operator on Oracle and PostgreSQL.
The LIKE operator wildcard generated for contains, startswith, endswith and their case-insensitive variant lookups was conflicting with parameter interpolation on CREATE constraint statement execution. Ideally we'd delegate parameters interpolation in DDL statements on backends that support it but that would require backward incompatible changes to the Index and Constraint SQL generating methods. Thanks David Sanders for the report. Backport of a8b3f96f6acfa082f99166e0a1cfb4b0fbc0eace from master
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/oracle/schema.py2
-rw-r--r--django/db/backends/postgresql/schema.py2
2 files changed, 3 insertions, 1 deletions
diff --git a/django/db/backends/oracle/schema.py b/django/db/backends/oracle/schema.py
index 0664a4ded5..953d2909ea 100644
--- a/django/db/backends/oracle/schema.py
+++ b/django/db/backends/oracle/schema.py
@@ -22,7 +22,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
if isinstance(value, (datetime.date, datetime.time, datetime.datetime)):
return "'%s'" % value
elif isinstance(value, str):
- return "'%s'" % value.replace("\'", "\'\'")
+ return "'%s'" % value.replace("\'", "\'\'").replace('%', '%%')
elif isinstance(value, (bytes, bytearray, memoryview)):
return "'%s'" % value.hex()
elif isinstance(value, bool):
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index 7d3482399e..994f43cc55 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -22,6 +22,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_delete_procedure = 'DROP FUNCTION %(procedure)s(%(param_types)s)'
def quote_value(self, value):
+ if isinstance(value, str):
+ value = value.replace('%', '%%')
# getquoted() returns a quoted bytestring of the adapted value.
return psycopg2.extensions.adapt(value).getquoted().decode()