From 6294fc7179011847d8a9f906cf4939ebf9852265 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 12 Aug 2008 07:52:33 +0000 Subject: [PATCH] Changed "exact" matches in MySQL to use the database's native collation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- django/db/backends/mysql/base.py | 4 ++-- docs/db-api.txt | 13 +++++++++++++ tests/regressiontests/string_lookup/models.py | 6 ------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 6e8eb187d3..8afaa1f03c 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -153,9 +153,9 @@ class DatabaseOperations(BaseDatabaseOperations): return [first % value, second % value] class DatabaseWrapper(BaseDatabaseWrapper): - + operators = { - 'exact': '= BINARY %s', + 'exact': '= %s', 'iexact': 'LIKE %s', 'contains': 'LIKE BINARY %s', 'icontains': 'LIKE %s', diff --git a/docs/db-api.txt b/docs/db-api.txt index b014a70b1e..ca7d47f8fa 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -1327,6 +1327,19 @@ changed in the development version. Previously, it was (intentionally) converted to ``WHERE id = NULL`` at the SQL level, which would never match anything. It has now been changed to behave the same as ``id__isnull=True``. +.. admonition:: MySQL comparisons + + In MySQL, whether or not ``exact`` comparisons are case-sensitive depends + upon the collation setting of the table involved. The default is usually + ``latin1_swedish_ci`` or ``utf8_swedish_ci``, which results in + case-insensitive comparisons. Change the collation to + ``latin1_swedish_cs`` or ``utf8_bin`` for case sensitive comparisons. + + For more details, refer to the MySQL manual section about `character sets + and collations`_. + +.. _character sets and collations: http://dev.mysql.com/doc/refman/5.0/en/charset.html + iexact ~~~~~~ diff --git a/tests/regressiontests/string_lookup/models.py b/tests/regressiontests/string_lookup/models.py index 39e7955592..1bdb2d4452 100644 --- a/tests/regressiontests/string_lookup/models.py +++ b/tests/regressiontests/string_lookup/models.py @@ -97,12 +97,6 @@ __test__ = {'API_TESTS': ur""" >>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.') -# Regression tests for #2170: test case sensitiveness ->>> Article.objects.filter(text__exact='tHe qUick bRown fOx jUmps over tHe lazy dog.') -[] ->>> Article.objects.filter(text__iexact='tHe qUick bRown fOx jUmps over tHe lazy dog.') -[] - >>> Article.objects.get(text__contains='quick brown fox')