Code

Ticket #3575: django_db.diff

File django_db.diff, 1.5 KB (added by Jack Moffitt <metajack@…>, 7 years ago)

patch to make iexact searches use LOWER() instead of ILIKE

Line 
1Index: django/db/models/query.py
2===================================================================
3--- django/db/models/query.py   (revision 5132)
4+++ django/db/models/query.py   (revision 5133)
5@@ -636,8 +636,12 @@
6     if table_prefix.endswith('.'):
7         table_prefix = backend.quote_name(table_prefix[:-1])+'.'
8     field_name = backend.quote_name(field_name)
9+    # Grab mapping for table and column name to do formatting
10+    column_map = '%s%s' % (table_prefix, field_name)
11+    if hasattr(backend, 'COLUMN_MAPPING') and backend.COLUMN_MAPPING.has_key(lookup_type):
12+        column_map = backend.COLUMN_MAPPING[lookup_type] % column_map
13     try:
14-        return '%s%s %s' % (table_prefix, field_name, (backend.OPERATOR_MAPPING[lookup_type] % '%s'))
15+        return '%s %s' % (column_map, (backend.OPERATOR_MAPPING[lookup_type] % '%s'))
16     except KeyError:
17         pass
18     if lookup_type == 'in':
19Index: django/db/backends/postgresql_psycopg2/base.py
20===================================================================
21--- django/db/backends/postgresql_psycopg2/base.py      (revision 5132)
22+++ django/db/backends/postgresql_psycopg2/base.py      (revision 5133)
23@@ -120,9 +120,14 @@
24 def get_pk_default_value():
25     return "DEFAULT"
26 
27+# Create a map for to do column functions
28+COLUMN_MAPPING = {
29+    'iexact': 'LOWER(%s)',
30+    }
31+
32 OPERATOR_MAPPING = {
33     'exact': '= %s',
34-    'iexact': 'ILIKE %s',
35+    'iexact': '= LOWER(%s)',
36     'contains': 'LIKE %s',
37     'icontains': 'ILIKE %s',
38     'gt': '> %s',