From d22e8e9009cbe46fcb80b477730dda91ed4f9369 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:53:12 +0100 Subject: [PATCH] str_like case sensitivity If ignore_case is true, an error is thrown for dbms without ILIKE. If ignore_case is false, LIKE is used consistently across dbms --- R/backend-.R | 9 +++++++-- tests/testthat/_snaps/backend-.md | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/R/backend-.R b/R/backend-.R index 3557e252d..862d41bd8 100644 --- a/R/backend-.R +++ b/R/backend-.R @@ -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) } }, diff --git a/tests/testthat/_snaps/backend-.md b/tests/testthat/_snaps/backend-.md index b2e003bc5..5b414ab16 100644 --- a/tests/testthat/_snaps/backend-.md +++ b/tests/testthat/_snaps/backend-.md @@ -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()`.