Skip to content

Commit

Permalink
Add dbQuoteIdentifier support for dbplyr_table_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jarodmeng committed Dec 24, 2024
1 parent 08d4376 commit 0009cc1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
57 changes: 56 additions & 1 deletion R/dbQuoteIdentifier.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NULL
schema = as.character(x$schema),
table = as.character(x$table)
)
DBI::dbQuoteIdentifier(conn, x_id)
DBI::dbQuoteIdentifier(conn, x_id, ...)
}

setOldClass("dbplyr_schema")
Expand All @@ -28,3 +28,58 @@ setMethod(
signature("PrestoConnection", "dbplyr_schema"),
.dbQuoteIdentifier_PrestoConnection_dbplyr_schema
)

#' @rdname PrestoConnection-class
#' @inheritParams DBI::dbQuoteIdentifier
#' @usage NULL
.dbQuoteIdentifier_PrestoConnection_dbplyr_table_path <- function(conn, x, ...) {
x_components <- dbplyr::table_path_components(x, conn)[[1]]
if (length(x_components) == 3L) {
if (x_components[1] != conn@catalog) {
stop("Mismatched catalogs", call. = FALSE)
}
x_components <- x_components[2L:3L]
}
if (length(x_components) == 2L) {
x_id <- DBI::Id(
schema = as.character(x_components[1]),
table = as.character(x_components[2])
)
x_qid <- DBI::dbQuoteIdentifier(conn, x_id, ...)
}
if (length(x_components) == 1L) {
x_qid <- DBI::dbQuoteIdentifier(conn, x_components, ...)
}
return(x_qid)
}

setOldClass("dbplyr_table_path")

#' @rdname PrestoConnection-class
#' @importMethodsFrom DBI dbQuoteIdentifier
#' @export
setMethod(
"dbQuoteIdentifier",
signature("PrestoConnection", "dbplyr_table_path"),
.dbQuoteIdentifier_PrestoConnection_dbplyr_table_path
)

#' @rdname PrestoConnection-class
#' @inheritParams DBI::dbQuoteIdentifier
#' @usage NULL
.dbQuoteIdentifier_PrestoConnection_AsIs <- function(conn, x, ...) {
if (utils::packageVersion("dbplyr") < "2.5.0") {
stop("Using I() in table name required dbplyr >= 2.5.0", call. = FALSE)
}
x_tp <- dbplyr::as_table_path(x, conn)
dbQuoteIdentifier(conn, x_tp, ...)
}

#' @rdname PrestoConnection-class
#' @importMethodsFrom DBI dbQuoteIdentifier
#' @export
setMethod(
"dbQuoteIdentifier",
signature("PrestoConnection", "AsIs"),
.dbQuoteIdentifier_PrestoConnection_AsIs
)
8 changes: 8 additions & 0 deletions man/PrestoConnection-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0009cc1

Please sign in to comment.