tests/testthat/test-dbQuoteIdentifier__duckdb_connection.R

test_that("only quotes where needed", {
  con <- dbConnect(duckdb())
  on.exit(dbDisconnect(con, shutdown = TRUE))

  expect_equal(
    dbQuoteIdentifier(con, c("x y", "select", "SELECT", "x")),
    SQL(c('"x y"', '"select"', '"SELECT"', "x"))
  )
})

test_that("preserves expected DBI behaviour", {
  con <- dbConnect(duckdb())
  on.exit(dbDisconnect(con, shutdown = TRUE))

  expect_equal(dbQuoteIdentifier(con, SQL("SELECT")), SQL("SELECT"))
  expect_equal(dbQuoteIdentifier(con, character()), SQL(character()))
  expect_equal(dbQuoteIdentifier(con, c(a = "a")), SQL("a", names = "a"))

  expect_equal(
    dbQuoteIdentifier(con, Id(schema = "a", table = "b")),
    SQL("a.b")
  )
  expect_equal(
    dbQuoteIdentifier(con, Id(schema = "SELECT", table = "b")),
    SQL('"SELECT".b')
  )
})

Try the duckdb package in your browser

Any scripts or data that you put into this service are public.

duckdb documentation built on Nov. 17, 2023, 5:08 p.m.