Skip to content
Merged
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Depends:
Imports:
bit64,
blob (>= 1.2.0),
DBI (>= 1.1.0),
DBI (>= 1.2.0),
hms (>= 1.0.0),
lubridate,
methods,
withr
Suggests:
callr,
covr,
DBItest (>= 1.7.2.9001),
DBItest (>= 1.7.3),
knitr,
rlang,
rmarkdown,
Expand Down
15 changes: 1 addition & 14 deletions R/dbQuoteIdentifier_PqConnection_Id.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
#' @name quote
#' @usage NULL
dbQuoteIdentifier_PqConnection_Id <- function(conn, x, ...) {
stopifnot(all(names(x@name) %in% c("catalog", "schema", "table")))
stopifnot(!anyDuplicated(names(x@name)))

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

#' @rdname quote
Expand Down
67 changes: 64 additions & 3 deletions tests/testthat/test-dbQuoteIdentifier.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,74 @@ test_that("quoting SQL", {
"Robert'); DROP TABLE Students;--")
})

test_that("quoting Id", {
test_that("quoting Id, table", {
con <- postgresDefault()

quoted <- dbQuoteIdentifier(con, Id(table = 'Students;--'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Students;--"')
})

test_that("quoting Id, table, unnamed", {
con <- postgresDefault()

quoted <- dbQuoteIdentifier(con, Id('Students;--'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Students;--"')
})

test_that("quoting Id, schema", {
con <- postgresDefault()

quoted <- dbQuoteIdentifier(con, Id(schema = 'Robert'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Robert"')
})

test_that("quoting Id, schema, unnamed", {
con <- postgresDefault()

quoted <- dbQuoteIdentifier(con, Id('Robert'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Robert"')
})

test_that("quoting Id, fully-qualified table", {
con <- postgresDefault()

quoted <- dbQuoteIdentifier(con, Id(schema = 'Robert', table = 'Students;--'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted),
'"Robert"."Students;--"')
expect_equal(as.character(quoted), '"Robert"."Students;--"')
})

test_that("quoting Id, fully-qualified column, #263", {
con <- postgresDefault()

quoted <-
dbQuoteIdentifier(
con,
Id(schema = "Robert", table = "Students;--", column = "dormitory")
)
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Robert"."Students;--"."dormitory"')
})

test_that("quoting Id, column, unordered", {
con <- postgresDefault()

quoted <-
dbQuoteIdentifier(con, Id(column = "dormitory", table = 'Students;--'))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Students;--"."dormitory"')
})

test_that("quoting Id, fully-qualified column, unnamed", {
con <- postgresDefault()

quoted <-
dbQuoteIdentifier(con, Id('Robert', 'Students;--', "dormitory"))
expect_s4_class(quoted, 'SQL')
expect_equal(as.character(quoted), '"Robert"."Students;--"."dormitory"')
})

test_that("unquoting identifier - SQL with quotes", {
Expand Down