diff options
| author | Tom <tom@tomforb.es> | 2018-06-19 23:24:43 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-06-20 10:57:28 -0400 |
| commit | 42490768441701bc02255b22df8e6894cbe487c7 (patch) | |
| tree | 882f2d43b8137d423b219a2e62c8c203e66a704a /django | |
| parent | b0fbfae09334554124e1dccb7559d10f36e2f84c (diff) | |
Refs #29451 -- Fixed regex/iregex lookups on MySQL 8.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 2 | ||||
| -rw-r--r-- | django/db/backends/mysql/operations.py | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index ea6f50ef1c..91e0e83242 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -141,8 +141,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 e5c0c5c71b..47e179db41 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -282,3 +282,14 @@ class DatabaseOperations(BaseDatabaseOperations): # EXTENDED and FORMAT are mutually exclusive options. prefix += ' EXTENDED' return prefix + + 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 |
