Skip to content

Commit 6f52ffe

Browse files
Closed issue2550805 (Postgresql should search title case insensitive), by Tom Ekberg.
1 parent 455ac33 commit 6f52ffe

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Features:
5151

5252
Fixed:
5353

54+
- issue2550805: Postgres should search title attribute case insensitive
55+
like sqlite. Reported and fixed by Tom Ekberg. (Bernhard Reiter)
5456
- Removed some old left over "rlog" references in documentation and code.
5557
Makes the debugging.txt advise for the database unit tests work again.
5658
- Fixed OpenPGP support for modern versions of libgpgme. (Bernhard Reiter)

roundup/backends/back_postgresql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def clear(self):
285285

286286
class PostgresqlClass:
287287
order_by_null_values = '(%s is not NULL)'
288+
case_insensitive_like = 'ILIKE'
288289

289290
class Class(PostgresqlClass, rdbms_common.Class):
290291
pass

roundup/backends/rdbms_common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,14 @@ def _filter_sql (self, search_matches, filterspec, srt=[], grp=[], retr=0):
24402440

24412441
# now add to the where clause
24422442
where.append('('
2443-
+' and '.join(["_%s._%s LIKE '%s'"%(pln, k, s) for s in v])
2443+
+' and '.join(["_%s._%s %s '%s'"%(
2444+
pln,
2445+
k,
2446+
# For many databases the LIKE operator
2447+
# ignores case. Postgres and Oracle have
2448+
# an ILIKE operator to support this.
2449+
getattr(self,'case_insensitive_like','LIKE'),
2450+
s) for s in v])
24442451
+')')
24452452
# note: args are embedded in the query string now
24462453
if 'sort' in p.need_for:

test/db_test_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,23 @@ def testFilteringString(self):
12351235
ae(filt(None, {'title': ['one', 'two']}, ('+','id'), (None,None)),
12361236
[])
12371237

1238+
def testFilteringStringCase(self):
1239+
"""
1240+
Similar to testFilteringString except the search parameters
1241+
have different capitalization.
1242+
"""
1243+
ae, filter, filter_iter = self.filteringSetup()
1244+
for filt in filter, filter_iter:
1245+
ae(filt(None, {'title': ['One']}, ('+','id'), (None,None)), ['1'])
1246+
ae(filt(None, {'title': ['Issue One']}, ('+','id'), (None,None)),
1247+
['1'])
1248+
ae(filt(None, {'title': ['ISSUE', 'ONE']}, ('+','id'), (None,None)),
1249+
['1'])
1250+
ae(filt(None, {'title': ['iSSUE']}, ('+','id'), (None,None)),
1251+
['1','2','3'])
1252+
ae(filt(None, {'title': ['One', 'Two']}, ('+','id'), (None,None)),
1253+
[])
1254+
12381255
def testFilteringLink(self):
12391256
ae, filter, filter_iter = self.filteringSetup()
12401257
a = 'assignedto'

0 commit comments

Comments
 (0)