Refs #29451 -- Fixed regex/iregex lookups on MySQL 8.

This commit is contained in:
Tom 2018-06-19 23:24:43 +01:00 committed by Tim Graham
parent b0fbfae093
commit 4249076844
3 changed files with 13 additions and 2 deletions

View File

@ -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',

View File

@ -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

View File

@ -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`).