Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6294fc7179011847d8a9f906cf4939ebf9852265 1 parent ca71eac
Malcolm Tredinnick authored August 12, 2008
4  django/db/backends/mysql/base.py
@@ -153,9 +153,9 @@ def year_lookup_bounds(self, value):
153 153
         return [first % value, second % value]
154 154
 
155 155
 class DatabaseWrapper(BaseDatabaseWrapper):
156  
-    
  156
+
157 157
     operators = {
158  
-        'exact': '= BINARY %s',
  158
+        'exact': '= %s',
159 159
         'iexact': 'LIKE %s',
160 160
         'contains': 'LIKE BINARY %s',
161 161
         'icontains': 'LIKE %s',
13  docs/db-api.txt
@@ -1327,6 +1327,19 @@ changed in the development version. Previously, it was (intentionally)
1327 1327
 converted to ``WHERE id = NULL`` at the SQL level, which would never match
1328 1328
 anything. It has now been changed to behave the same as ``id__isnull=True``.
1329 1329
 
  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
+
1330 1343
 iexact
1331 1344
 ~~~~~~
1332 1345
 
6  tests/regressiontests/string_lookup/models.py
@@ -97,12 +97,6 @@ def __str__(self):
97 97
 >>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.')
98 98
 <Article: Article Test>
99 99
 
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  
-
106 100
 >>> Article.objects.get(text__contains='quick brown fox')
107 101
 <Article: Article Test>
108 102
 

0 notes on commit 6294fc7

Please sign in to comment.
Something went wrong with that request. Please try again.