Skip to content

Commit 4c99316

Browse files
authored
Merge pull request #372 from dpprdan/fix/col_in_dbQuoteIdentifier
2 parents 5d2eadf + 153ec24 commit 4c99316

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ Depends:
2222
Imports:
2323
bit64,
2424
blob (>= 1.2.0),
25-
DBI (>= 1.1.0),
25+
DBI (>= 1.2.0),
2626
hms (>= 1.0.0),
2727
lubridate,
2828
methods,
2929
withr
3030
Suggests:
3131
callr,
3232
covr,
33-
DBItest (>= 1.7.2.9001),
33+
DBItest (>= 1.7.3),
3434
knitr,
3535
rlang,
3636
rmarkdown,

tests/testthat/test-dbQuoteIdentifier.R

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,74 @@ test_that("quoting SQL", {
1616
"Robert'); DROP TABLE Students;--")
1717
})
1818

19-
test_that("quoting Id", {
19+
test_that("quoting Id, table", {
20+
con <- postgresDefault()
21+
22+
quoted <- dbQuoteIdentifier(con, Id(table = 'Students;--'))
23+
expect_s4_class(quoted, 'SQL')
24+
expect_equal(as.character(quoted), '"Students;--"')
25+
})
26+
27+
test_that("quoting Id, table, unnamed", {
28+
con <- postgresDefault()
29+
30+
quoted <- dbQuoteIdentifier(con, Id('Students;--'))
31+
expect_s4_class(quoted, 'SQL')
32+
expect_equal(as.character(quoted), '"Students;--"')
33+
})
34+
35+
test_that("quoting Id, schema", {
36+
con <- postgresDefault()
37+
38+
quoted <- dbQuoteIdentifier(con, Id(schema = 'Robert'))
39+
expect_s4_class(quoted, 'SQL')
40+
expect_equal(as.character(quoted), '"Robert"')
41+
})
42+
43+
test_that("quoting Id, schema, unnamed", {
44+
con <- postgresDefault()
45+
46+
quoted <- dbQuoteIdentifier(con, Id('Robert'))
47+
expect_s4_class(quoted, 'SQL')
48+
expect_equal(as.character(quoted), '"Robert"')
49+
})
50+
51+
test_that("quoting Id, fully-qualified table", {
2052
con <- postgresDefault()
2153

2254
quoted <- dbQuoteIdentifier(con, Id(schema = 'Robert', table = 'Students;--'))
2355
expect_s4_class(quoted, 'SQL')
24-
expect_equal(as.character(quoted),
25-
'"Robert"."Students;--"')
56+
expect_equal(as.character(quoted), '"Robert"."Students;--"')
57+
})
58+
59+
test_that("quoting Id, fully-qualified column, #263", {
60+
con <- postgresDefault()
61+
62+
quoted <-
63+
dbQuoteIdentifier(
64+
con,
65+
Id(schema = "Robert", table = "Students;--", column = "dormitory")
66+
)
67+
expect_s4_class(quoted, 'SQL')
68+
expect_equal(as.character(quoted), '"Robert"."Students;--"."dormitory"')
69+
})
70+
71+
test_that("quoting Id, column, unordered", {
72+
con <- postgresDefault()
73+
74+
quoted <-
75+
dbQuoteIdentifier(con, Id(column = "dormitory", table = 'Students;--'))
76+
expect_s4_class(quoted, 'SQL')
77+
expect_equal(as.character(quoted), '"Students;--"."dormitory"')
78+
})
79+
80+
test_that("quoting Id, fully-qualified column, unnamed", {
81+
con <- postgresDefault()
82+
83+
quoted <-
84+
dbQuoteIdentifier(con, Id('Robert', 'Students;--', "dormitory"))
85+
expect_s4_class(quoted, 'SQL')
86+
expect_equal(as.character(quoted), '"Robert"."Students;--"."dormitory"')
2687
})
2788

2889
test_that("unquoting identifier - SQL with quotes", {

0 commit comments

Comments
 (0)