@@ -47,14 +47,15 @@ def contains(self, compiler, connection):
4747 params = list (lhs_params )
4848 params .extend (rhs_params )
4949 is_icontains = self .lookup_name .startswith ("i" )
50- if self .rhs_is_direct_value () and params and not self .bilateral_transforms :
50+ if self .rhs_is_direct_value () and rhs_params and not self .bilateral_transforms :
5151 rhs_sql = self .get_rhs_op (connection , rhs_sql )
52+ rhs_idx = len (lhs_params )
5253 # Chop the leading and trailing percent signs that Django adds to the
5354 # param since this isn't a LIKE query as Django expects.
54- params [0 ] = params [0 ][1 :- 1 ]
55+ params [rhs_idx ] = params [rhs_idx ][1 :- 1 ]
5556 # Add the case insensitive flag for icontains.
5657 if is_icontains :
57- params [0 ] = "(?i)" + params [0 ]
58+ params [rhs_idx ] = "(?i)" + params [rhs_idx ]
5859 # rhs_sql is REGEXP_CONTAINS(%s, %%s), and lhs_sql is the column name.
5960 return rhs_sql % lhs_sql , tuple (params )
6061 else :
@@ -96,8 +97,9 @@ def iexact(self, compiler, connection):
9697 params .extend (rhs_params )
9798 rhs_sql = self .get_rhs_op (connection , rhs_sql )
9899 # Wrap the parameter in ^ and $ to restrict the regex to an exact match.
99- if self .rhs_is_direct_value () and params and not self .bilateral_transforms :
100- params [0 ] = "^(?i)%s$" % params [0 ]
100+ if self .rhs_is_direct_value () and rhs_params and not self .bilateral_transforms :
101+ rhs_idx = len (lhs_params )
102+ params [rhs_idx ] = "^(?i)%s$" % params [rhs_idx ]
101103 else :
102104 # lhs_sql is the expression/column to use as the regular expression.
103105 # Use concat to make the value case-insensitive.
@@ -143,12 +145,13 @@ def regex(self, compiler, connection):
143145 params = list (lhs_params )
144146 params .extend (rhs_params )
145147 is_iregex = self .lookup_name .startswith ("i" )
146- if self .rhs_is_direct_value () and params and not self .bilateral_transforms :
148+ if self .rhs_is_direct_value () and rhs_params and not self .bilateral_transforms :
147149 rhs_sql = self .get_rhs_op (connection , rhs_sql )
150+ rhs_idx = len (lhs_params )
148151 if is_iregex :
149- params [0 ] = "(?i)%s" % params [0 ]
152+ params [rhs_idx ] = "(?i)%s" % params [rhs_idx ]
150153 else :
151- params [0 ] = str (params [0 ])
154+ params [rhs_idx ] = str (params [rhs_idx ])
152155 # rhs_sql is REGEXP_CONTAINS(%s, %%s), and lhs_sql is the column name.
153156 return rhs_sql % lhs_sql , tuple (params )
154157 else :
@@ -191,15 +194,16 @@ def startswith_endswith(self, compiler, connection):
191194 is_insensitive = self .lookup_name .startswith ("i" )
192195 # Chop the leading (endswith) or trailing (startswith) percent sign that
193196 # Django adds to the param since this isn't a LIKE query as Django expects.
194- if self .rhs_is_direct_value () and params and not self .bilateral_transforms :
197+ if self .rhs_is_direct_value () and rhs_params and not self .bilateral_transforms :
195198 rhs_sql = self .get_rhs_op (connection , rhs_sql )
199+ rhs_idx = len (lhs_params )
196200 if is_endswith :
197- params [0 ] = str (params [0 ][1 :]) + "$"
201+ params [rhs_idx ] = str (params [rhs_idx ][1 :]) + "$"
198202 else :
199- params [0 ] = "^" + str (params [0 ][:- 1 ])
203+ params [rhs_idx ] = "^" + str (params [rhs_idx ][:- 1 ])
200204 # Add the case insensitive flag for istartswith or iendswith.
201205 if is_insensitive :
202- params [0 ] = "(?i)" + params [0 ]
206+ params [rhs_idx ] = "(?i)" + params [rhs_idx ]
203207 # rhs_sql is REGEXP_CONTAINS(%s, %%s), and lhs_sql is the column name.
204208 return rhs_sql % lhs_sql , tuple (params )
205209 else :
0 commit comments