Skip to content

Commit

Permalink
Merge pull request #372 from dpprdan/fix/col_in_dbQuoteIdentifier
Browse files Browse the repository at this point in the history
krlmlr authored Apr 1, 2024
2 parents 5d2eadf + 153ec24 commit 4c99316
Showing 2 changed files with 66 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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,
67 changes: 64 additions & 3 deletions tests/testthat/test-dbQuoteIdentifier.R
Original file line number Diff line number Diff line change
@@ -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", {

0 comments on commit 4c99316

Please sign in to comment.