From 7136eb8f3a052afef29e343679e84e93d7e9e0a3 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 1 Nov 2005 01:08:13 +0000 Subject: [PATCH] Fixed #507 -- Changed MySQL backend so that it uses 'LIKE BINARY' for case-sensitive comparisons -- contains, startswith and endswith. Thanks, Simon git-svn-id: http://code.djangoproject.com/svn/django/trunk@1036 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/db/backends/mysql.py | 6 +++--- docs/db-api.txt | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py index 4399b6a6a0..23815a80cb 100644 --- a/django/core/db/backends/mysql.py +++ b/django/core/db/backends/mysql.py @@ -125,15 +125,15 @@ def get_relations(cursor, table_name): OPERATOR_MAPPING = { 'exact': '=', 'iexact': 'LIKE', - 'contains': 'LIKE', + 'contains': 'LIKE BINARY', 'icontains': 'LIKE', 'ne': '!=', 'gt': '>', 'gte': '>=', 'lt': '<', 'lte': '<=', - 'startswith': 'LIKE', - 'endswith': 'LIKE', + 'startswith': 'LIKE BINARY', + 'endswith': 'LIKE BINARY', 'istartswith': 'LIKE', 'iendswith': 'LIKE', } diff --git a/docs/db-api.txt b/docs/db-api.txt index b80d4e8647..1a4f488d50 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -161,9 +161,9 @@ The DB API supports the following lookup types: ``foo``, ``FOO``, ``fOo``, etc. contains Case-sensitive containment test: ``polls.get_list(question__contains="spam")`` returns all polls - that contain "spam" in the question. (PostgreSQL only. MySQL - doesn't support case-sensitive LIKE statements; ``contains`` - will act like ``icontains`` for MySQL.) + that contain "spam" in the question. (PostgreSQL and MySQL + only. SQLite doesn't support case-sensitive LIKE statements; + ``contains`` will act like ``icontains`` for SQLite.) icontains Case-insensitive containment test. gt Greater than: ``polls.get_list(id__gt=4)``. gte Greater than or equal to. @@ -174,11 +174,10 @@ The DB API supports the following lookup types: a list of polls whose IDs are either 1, 3 or 4. startswith Case-sensitive starts-with: ``polls.get_list(question_startswith="Would")``. (PostgreSQL - only. MySQL doesn't support case-sensitive LIKE statements; - ``startswith`` will act like ``istartswith`` for MySQL.) - endswith Case-sensitive ends-with. (PostgreSQL only. MySQL doesn't - support case-sensitive LIKE statements; ``endswith`` will act - like ``iendswith`` for MySQL.) + and MySQL only. SQLite doesn't support case-sensitive LIKE + statements; ``startswith`` will act like ``istartswith`` for + SQLite.) + endswith Case-sensitive ends-with. (PostgreSQL and MySQL only.) istartswith Case-insensitive starts-with. iendswith Case-insensitive ends-with. range Range test: