@@ -33,6 +33,7 @@ def __init__(self, sess, *args, **kwargs):
3333 self .sess = sess
3434 self .columns = OrderedDict ()
3535 self .criteria = []
36+ self .case_sensitive = kwargs .pop ('case_sensitive' , True )
3637 self ._limit = - 1
3738 self ._offset = 0
3839 self ._continue_index = 0
@@ -52,6 +53,7 @@ def _clone(self):
5253 new_q = Query (self .sess )
5354 new_q .columns = self .columns
5455 new_q .criteria = self .criteria
56+ new_q .case_sensitive = self .case_sensitive
5557 new_q ._limit = self ._limit
5658 new_q ._offset = self ._offset
5759 new_q ._continue_index = self ._continue_index
@@ -65,7 +67,28 @@ def add_keyword(self, keyword, value = ''):
6567
6668 def filter (self , * criteria ):
6769 new_q = self ._clone ()
68- new_q .criteria += list (criteria )
70+
71+ if self .case_sensitive :
72+ new_q .criteria += list (criteria )
73+ else :
74+ # In case-insensitive mode, all criterion values are converted
75+ # to uppercase here, and the UPPER_CASE_WHERE option is enabled
76+ # when creating a new GenQueryRequest in the _message function.
77+ # Converting both keys and values to uppercase results in
78+ # case-insensitive queries.
79+ for criterion in criteria :
80+ if type (criterion .value ) == str :
81+ criterion .value = str .upper (
82+ criterion .value )
83+ elif type (criterion .value ) == list :
84+ criterion .value = [str .upper (c ) if type (c ) == str
85+ else c for c in criterion .value ]
86+ elif type (criterion .value ) == tuple :
87+ criterion .value = tuple (
88+ [str .upper (c ) if type (c ) == str else c for c in
89+ list (criterion .value )])
90+ new_q .criteria .append (criterion )
91+
6992 return new_q
7093
7194 def order_by (self , column , order = 'asc' ):
@@ -132,7 +155,7 @@ def _select_message(self):
132155 # lists
133156 def _conds_message (self ):
134157 dct = _OrderedMultiMapping ([
135- (criterion .query_key .icat_id , criterion .op + ' ' + criterion .value )
158+ (criterion .query_key .icat_id , criterion .op + ' ' + criterion .irods_value )
136159 for criterion in self .criteria
137160 if isinstance (criterion .query_key , Column )
138161 ])
@@ -141,7 +164,7 @@ def _conds_message(self):
141164 def _kw_message (self ):
142165 dct = dict ([
143166 (criterion .query_key .icat_key ,
144- criterion .op + ' ' + criterion .value )
167+ criterion .op + ' ' + criterion .irods_value )
145168 for criterion in self .criteria
146169 if isinstance (criterion .query_key , Keyword )
147170 ])
@@ -155,7 +178,7 @@ def _message(self):
155178 'maxRows' : max_rows ,
156179 'continueInx' : self ._continue_index ,
157180 'partialStartIndex' : self ._offset ,
158- 'options' : 0 ,
181+ 'options' : 0 if self . case_sensitive else query_number [ 'UPPER_CASE_WHERE' ] ,
159182 'KeyValPair_PI' : self ._kw_message (),
160183 'InxIvalPair_PI' : self ._select_message (),
161184 'InxValPair_PI' : self ._conds_message ()
0 commit comments