tests/testthat/test-quote.R

test_that("quoting works", {
  con_mockmaria <- con_rpostgres <- list()
  class(con_mockmaria) <- "DBIMockMariaDBConnection"
  class(con_rpostgres) <- "DBIMockRPostgresConnection"

  some_sql <- SQL("foo")

  expect_identical(dbQuoteString(con_mockmaria, some_sql), some_sql)
  expect_identical(dbQuoteString(con_rpostgres, some_sql), some_sql)

  expect_identical(dbQuoteIdentifier(con_mockmaria, some_sql), some_sql)
  expect_identical(dbQuoteIdentifier(con_rpostgres, some_sql), some_sql)

  expect_identical(dbQuoteString(con_mockmaria, "foo"), SQL("'foo'"))
  expect_identical(dbQuoteString(con_rpostgres, "foo"), SQL("'foo'"))
  expect_identical(dbQuoteIdentifier(con_rpostgres, "foo"), SQL('"foo"'))
  # dplyr ident-style
  expect_identical(
    dbQuoteIdentifier(con_rpostgres, '"rpostgres"."airlines"'),
    SQL('"""rpostgres"".""airlines"""')
  )
  # However, MariaDB is slightly different (we haven't redefined it, since it
  # doesn't communicate with the DB first)
  expect_identical(dbQuoteIdentifier(con_mockmaria, "foo"), SQL("`foo`"))
})

Try the dittodb package in your browser

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

dittodb documentation built on June 22, 2024, 6:52 p.m.