Code

Ticket #8102: 8102-2.diff

File 8102-2.diff, 1.0 KB (added by kmtracey, 6 years ago)

Cast exact lookups to CHAR before specifying COLLATE to avoid problems with specifying collate on numeric/binary columns

Line 
1Index: django/db/backends/mysql/base.py
2===================================================================
3--- django/db/backends/mysql/base.py    (revision 8207)
4+++ django/db/backends/mysql/base.py    (working copy)
5@@ -145,18 +145,18 @@
6     features = DatabaseFeatures()
7     ops = DatabaseOperations()
8     operators = {
9-        'exact': '= BINARY %s',
10+        'exact': '= CAST(%s AS CHAR) COLLATE UTF8_BIN',
11         'iexact': 'LIKE %s',
12-        'contains': 'LIKE BINARY %s',
13+        'contains': 'LIKE %s COLLATE UTF8_BIN',
14         'icontains': 'LIKE %s',
15-        'regex': 'REGEXP BINARY %s',
16+        'regex': 'REGEXP %s COLLATE UTF8_BIN',
17         'iregex': 'REGEXP %s',
18         'gt': '> %s',
19         'gte': '>= %s',
20         'lt': '< %s',
21         'lte': '<= %s',
22-        'startswith': 'LIKE BINARY %s',
23-        'endswith': 'LIKE BINARY %s',
24+        'startswith': 'LIKE %s COLLATE UTF8_BIN',
25+        'endswith': 'LIKE %s COLLATE UTF8_BIN',
26         'istartswith': 'LIKE %s',
27         'iendswith': 'LIKE %s',
28     }