diff --git a/R/00-Id.R b/R/00-Id.R index fbbe51479..e20dfd4be 100644 --- a/R/00-Id.R +++ b/R/00-Id.R @@ -49,5 +49,10 @@ Id <- function(...) { #' @export toString.Id <- function(x, ...) { - paste0(" ", paste0('"', x@name, '"', collapse = ".")) + paste0(" ", dbQuoteIdentifier(ANSI(), x)) +} + + +dbQuoteIdentifier_DBIConnection_Id <- function(conn, x, ...) { + SQL(paste0(dbQuoteIdentifier(conn, x@name), collapse = ".")) } diff --git a/R/dbQuoteIdentifier_DBIConnection.R b/R/dbQuoteIdentifier_DBIConnection.R index 2fe31550f..05099f65c 100644 --- a/R/dbQuoteIdentifier_DBIConnection.R +++ b/R/dbQuoteIdentifier_DBIConnection.R @@ -3,9 +3,6 @@ dbQuoteIdentifier_DBIConnection <- function(conn, x, ...) { # Don't support lists, auto-vectorization violates type stability if (is(x, "SQL")) return(x) - if (is(x, "Id")) { - return(SQL(paste0(dbQuoteIdentifier(conn, x@name), collapse = "."))) - } if (!is.character(x)) stop("x must be character or SQL", call. = FALSE) if (any(is.na(x))) { @@ -37,4 +34,4 @@ setMethod("dbQuoteIdentifier", signature("DBIConnection", "SQL"), dbQuoteIdentif #' @rdname hidden_aliases #' @export -setMethod("dbQuoteIdentifier", signature("DBIConnection", "Id"), dbQuoteIdentifier_DBIConnection) +setMethod("dbQuoteIdentifier", signature("DBIConnection", "Id"), dbQuoteIdentifier_DBIConnection_Id) diff --git a/tests/testthat/_snaps/00-Id.md b/tests/testthat/_snaps/00-Id.md index 5379cd646..694ddfaa3 100644 --- a/tests/testthat/_snaps/00-Id.md +++ b/tests/testthat/_snaps/00-Id.md @@ -11,5 +11,5 @@ Code Id("a", "b") Output - a.b + "a"."b" diff --git a/tests/testthat/_snaps/00-Id.new.md b/tests/testthat/_snaps/00-Id.new.md deleted file mode 100644 index 694ddfaa3..000000000 --- a/tests/testthat/_snaps/00-Id.new.md +++ /dev/null @@ -1,15 +0,0 @@ -# Id() requires a character vector - - Code - Id(1) - Condition - Error: - ! All elements of `...` must be strings. - -# has a decent print method - - Code - Id("a", "b") - Output - "a"."b" - diff --git a/tests/testthat/test-00-Id.R b/tests/testthat/test-00-Id.R index e9a7331e0..1c408f360 100644 --- a/tests/testthat/test-00-Id.R +++ b/tests/testthat/test-00-Id.R @@ -5,3 +5,10 @@ test_that("Id() requires a character vector", { test_that("has a decent print method", { expect_snapshot(Id("a", "b")) }) + +test_that("each element is quoted individually", { + expect_equal( + DBI::dbQuoteIdentifier(ANSI(), Id("a", "b.c")), + SQL('"a"."b.c"') + ) +})