Skip to content

Commit

Permalink
str_like case sensitivity
Browse files Browse the repository at this point in the history
If ignore_case is true, an error is thrown for dbms without ILIKE. If ignore_case is false, LIKE is used consistently across dbms
  • Loading branch information
edward-burn committed Apr 4, 2024
1 parent f3baed5 commit d22e8e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions R/backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,14 @@ base_scalar <- sql_translator(
str_sub = sql_str_sub("SUBSTR"),
str_like = function(string, pattern, ignore_case = TRUE) {
if (isTRUE(ignore_case)) {
sql_expr(!!string %LIKE% !!pattern)
bullets <- c(
"Backend does not support case insensitve {.fn str_like}.",
i = "Set ignore_case = FALSE for case sensitive match.",
i = "Note, using `tolower()` to cast string and pattern to lower case would also achieve a case insenitive match."
)
abort(bullets)
} else {
cli::cli_abort("Backend only supports case insensitve {.fn str_like}.")
sql_expr(!!string %LIKE% !!pattern)
}
},

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/backend-.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# can translate case insensitive like

Code
test_translate_sql(str_like(x, "abc", ignore_case = FALSE))
test_translate_sql(str_like(x, "abc", ignore_case = TRUE))
Condition
Error in `str_like()`:
! Backend only supports case insensitve `str_like()`.
Expand Down

0 comments on commit d22e8e9

Please sign in to comment.