| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3a8d922 commit 2772b57
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,7 +100,10 @@ def iexact(self, compiler, connection): | |||
| 100 | 100 | # lhs_sql is the expression/column to use as the regular expression. | |
| 101 | 101 | # Use concat to make the value case-insensitive. | |
| 102 | 102 | lhs_sql = "CONCAT('^(?i)', " + lhs_sql + ", '$')" | |
| 103 | - rhs_sql = rhs_sql.replace("%%s", "%s") | ||
| 103 | + if not self.rhs_is_direct_value() and not params: | ||
| 104 | + # If rhs is not a direct value and parameter is not present we want | ||
| 105 | + # to have only 1 formatable argument in rhs_sql else we need 2. | ||
| 106 | + rhs_sql = rhs_sql.replace("%%s", "%s") | ||
| 104 | 107 | # rhs_sql is REGEXP_CONTAINS(%s, %%s), and lhs_sql is the column name. | |
| 105 | 108 | return rhs_sql % lhs_sql, params | |
| 106 | 109 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -283,3 +283,17 @@ def test_iexact_sql_query_case_insensitive_function_transform(self): | |||
| 283 | 283 | + "CONCAT('^(?i)', CAST(UPPER(tests_author.name) AS STRING), '$'))", | |
| 284 | 284 | ) | |
| 285 | 285 | self.assertEqual(params, ()) | |
| 286 | + | ||
| 287 | + def test_iexact_sql_query_case_insensitive_value_match(self): | ||
| 288 | + | ||
| 289 | + qs1 = Author.objects.filter(name__upper__iexact="abc").values("name") | ||
| 290 | + compiler = SQLCompiler(qs1.query, self.connection, "default") | ||
| 291 | + sql_compiled, params = compiler.as_sql() | ||
| 292 | + | ||
| 293 | + self.assertEqual( | ||
| 294 | + sql_compiled, | ||
| 295 | + "SELECT tests_author.name FROM tests_author WHERE " | ||
| 296 | + + "REGEXP_CONTAINS((UPPER(CONCAT('^(?i)', " | ||
| 297 | + + "CAST(UPPER(tests_author.name) AS STRING), '$'))), %s)", | ||
| 298 | + ) | ||
| 299 | + self.assertEqual(params, ("abc",)) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments