# Quoting ensures that arbitrary input is safe for use in a query
name <- "Robert'); DROP TABLE Students;--"
dbQuoteLiteral(ANSI(), name)
# NAs become NULL
dbQuoteLiteral(ANSI(), c(1:3, NA))
# Logicals become integers by default
dbQuoteLiteral(ANSI(), c(TRUE, FALSE, NA))
# Raw vectors become hex strings by default
dbQuoteLiteral(ANSI(), list(as.raw(1:3), NULL))
# SQL vectors are always passed through as is
var_name <- SQL("select")
var_name
dbQuoteLiteral(ANSI(), var_name)
# This mechanism is used to prevent double escaping
dbQuoteLiteral(ANSI(), dbQuoteLiteral(ANSI(), name))
Run the code above in your browser using DataLab