[2.0.x] Refs #29451 -- Fixed regex/iregex lookups on MySQL 8.

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

View File

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

View File

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

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