Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6294fc7

Browse files
committed
Changed "exact" matches in MySQL to use the database's native collation.
This effectively reverses the change in [7798]. It was proving too difficult to successfully manage all the side effects here and provide a satisfactory solution for everybody. Many thanks to arne, Martin von Löwis and, particular, Karen Tracey, for doing a lot of research and proto-patches here to establish what was possible and practical. This is backwards incompatible if you were relying on the behaviour after [7798]. The docs have been updated to indicate the solution. Refs #2170, #7789, #8102. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8319 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent ca71eac commit 6294fc7

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

‎django/db/backends/mysql/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def year_lookup_bounds(self, value):
153153
return [first % value, second % value]
154154

155155
class DatabaseWrapper(BaseDatabaseWrapper):
156-
156+
157157
operators = {
158-
'exact': '= BINARY %s',
158+
'exact': '= %s',
159159
'iexact': 'LIKE %s',
160160
'contains': 'LIKE BINARY %s',
161161
'icontains': 'LIKE %s',

‎docs/db-api.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,19 @@ changed in the development version. Previously, it was (intentionally)
13271327
converted to ``WHERE id = NULL`` at the SQL level, which would never match
13281328
anything. It has now been changed to behave the same as ``id__isnull=True``.
13291329

1330+
.. admonition:: MySQL comparisons
1331+
1332+
In MySQL, whether or not ``exact`` comparisons are case-sensitive depends
1333+
upon the collation setting of the table involved. The default is usually
1334+
``latin1_swedish_ci`` or ``utf8_swedish_ci``, which results in
1335+
case-insensitive comparisons. Change the collation to
1336+
``latin1_swedish_cs`` or ``utf8_bin`` for case sensitive comparisons.
1337+
1338+
For more details, refer to the MySQL manual section about `character sets
1339+
and collations`_.
1340+
1341+
.. _character sets and collations: http://dev.mysql.com/doc/refman/5.0/en/charset.html
1342+
13301343
iexact
13311344
~~~~~~
13321345

‎tests/regressiontests/string_lookup/models.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ def __str__(self):
9797
>>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.')
9898
<Article: Article Test>
9999
100-
# Regression tests for #2170: test case sensitiveness
101-
>>> Article.objects.filter(text__exact='tHe qUick bRown fOx jUmps over tHe lazy dog.')
102-
[]
103-
>>> Article.objects.filter(text__iexact='tHe qUick bRown fOx jUmps over tHe lazy dog.')
104-
[<Article: Article Test>]
105-
106100
>>> Article.objects.get(text__contains='quick brown fox')
107101
<Article: Article Test>
108102

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /