summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tom@tomforb.es>2018-06-19 23:24:43 +0100
committerTim Graham <timograham@gmail.com>2018-06-20 11:01:16 -0400
commitf8a6488839ac3666412bd3b5573cf7eae78fbcca (patch)
treed7cc8466aa6d2bffa34a7a1f81af8b32cb3e29fe
parent243f07bbb3e65c44500451a78251d062301fe25d (diff)
[2.0.x] Refs #29451 -- Fixed regex/iregex lookups on MySQL 8.
Backport of 42490768441701bc02255b22df8e6894cbe487c7 from master
-rw-r--r--django/db/backends/mysql/base.py2
-rw-r--r--django/db/backends/mysql/operations.py11
-rw-r--r--docs/releases/2.0.7.txt2
3 files changed, 13 insertions, 2 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 60d0e12124..34e8d41f03 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -148,8 +148,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'iexact': 'LIKE %s',
'contains': 'LIKE BINARY %s',
'icontains': 'LIKE %s',
- 'regex': 'REGEXP BINARY %s',
- 'iregex': 'REGEXP %s',
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index e4492f866f..d9cb6a27c0 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -272,3 +272,14 @@ class DatabaseOperations(BaseDatabaseOperations):
) % (lhs_sql, rhs_sql), lhs_params + rhs_params
else:
return "(TIMESTAMPDIFF(SECOND, %s, %s) * POW(10, 6))" % (rhs_sql, lhs_sql), rhs_params + lhs_params
+
+ def regex_lookup(self, lookup_type):
+ # REGEXP BINARY doesn't work correctly in MySQL 8+ and REGEXP_LIKE
+ # doesn't exist in MySQL 5.6.
+ if self.connection.mysql_version < (8, 0, 0):
+ if lookup_type == 'regex':
+ return '%s REGEXP BINARY %s'
+ return '%s REGEXP %s'
+
+ match_option = 'c' if lookup_type == 'regex' else 'i'
+ return "REGEXP_LIKE(%%s, %%s, '%s')" % match_option
diff --git a/docs/releases/2.0.7.txt b/docs/releases/2.0.7.txt
index 4890ee2dba..8d06deb226 100644
--- a/docs/releases/2.0.7.txt
+++ b/docs/releases/2.0.7.txt
@@ -14,3 +14,5 @@ Bugfixes
* Fixed admin check crash when using a query expression in
``ModelAdmin.ordering`` (:ticket:`29428`).
+
+* Fixed ``__regex`` and ``__iregex`` lookups with MySQL 8 (:ticket:`29451`).