Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions R/PqConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ setClass("PqConnection",
bigint = "character",
timezone = "character",
timezone_out = "character",
typnames = "data.frame"
typnames = "data.frame",
unquote_id = "logical"
)
)

Expand Down Expand Up @@ -164,6 +165,8 @@ setMethod("dbGetInfo", "PqConnection", function(dbObj, ...) {
#' set to [Sys.timezone()] or `""`.
#' This setting does not change the time values returned, only their display.
#' @param conn Connection to disconnect.
#' @param unquote_id Should driver unquote character automatically (before
#' quote the character)? Setting to `TRUE` convert character to Identifier before quote.
#' @export
#' @rdname Postgres
#' @examplesIf postgresHasDefault()
Expand All @@ -175,7 +178,7 @@ setMethod("dbConnect", "PqDriver",
function(drv, dbname = NULL,
host = NULL, port = NULL, password = NULL, user = NULL, service = NULL, ...,
bigint = c("integer64", "integer", "numeric", "character"),
check_interrupts = FALSE, timezone = "UTC", timezone_out = NULL) {
check_interrupts = FALSE, timezone = "UTC", timezone_out = NULL, unquote_id = FALSE) {

opts <- unlist(list(dbname = dbname, user = user, password = password,
host = host, port = as.character(port), service = service, client_encoding = "utf8", ...))
Expand All @@ -199,7 +202,7 @@ setMethod("dbConnect", "PqDriver",

# timezone is set later
conn <- new("PqConnection",
ptr = ptr, bigint = bigint, timezone = character(), typnames = data.frame()
ptr = ptr, bigint = bigint, timezone = character(), typnames = data.frame(), unquote_id = unquote_id
)
on.exit(dbDisconnect(conn))

Expand Down
2 changes: 1 addition & 1 deletion R/Redshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setMethod("dbConnect", "RedshiftDriver",
function(drv, dbname = NULL,
host = NULL, port = NULL, password = NULL, user = NULL, service = NULL, ...,
bigint = c("integer64", "integer", "numeric", "character"),
check_interrupts = FALSE, timezone = "UTC") {
check_interrupts = FALSE, timezone = "UTC", unquote_id = FALSE) {

new("RedshiftConnection", callNextMethod())
}
Expand Down
13 changes: 10 additions & 3 deletions R/quote.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ setMethod("dbQuoteString", c("PqConnection", "SQL"), function(conn, x, ...) {
#' @export
#' @rdname quote
setMethod("dbQuoteIdentifier", c("PqConnection", "character"), function(conn, x, ...) {
args <- list(...)
if (anyNA(x)) {
stop("Cannot pass NA to dbQuoteIdentifier()", call. = FALSE)
}
# Case where schema and table are character identifier
if(isTRUE(conn@unquote_id) && length(x) == 1 && is.null(args$id) && grepl("\\.", x) &&
!grepl("names\\((.*?)\\)", as.character(match.call())[[3]])) {
id <- dbUnquoteIdentifier(conn, SQL(x))[[1]]
return(dbQuoteIdentifier(conn, id, ...))
}
SQL(connection_quote_identifier(conn@ptr, x), names = names(x))
})

Expand All @@ -63,13 +70,13 @@ setMethod("dbQuoteIdentifier", c("PqConnection", "Id"), function(conn, x, ...) {

ret <- ""
if ("catalog" %in% names(x@name)) {
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["catalog"]]), ".")
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["catalog"]], id = "catalog"), ".")
}
if ("schema" %in% names(x@name)) {
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["schema"]]), ".")
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["schema"]], id = "schema"), ".")
}
if ("table" %in% names(x@name)) {
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["table"]]))
ret <- paste0(ret, dbQuoteIdentifier(conn, x@name[["table"]], id = "table"))
}
SQL(ret)
})
Expand Down