build_sql: Build a SQL string.

Description Usage Arguments Examples

View source: R/sql-escape.r

Description

This is a convenience function that should prevent sql injection attacks (which in the context of dplyr are most likely to be accidental not deliberate) by automatically escaping all expressions in the input, while treating bare strings as sql. This is unlikely to prevent any serious attack, but should make it unlikely that you produce invalid sql.

Usage

1
build_sql(..., .env = parent.frame(), con = NULL)

Arguments

...

input to convert to SQL. Use sql to preserve user input as is (dangerous), and ident to label user input as sql identifiers (safe)

.env

the environment in which to evalute the arguments. Should not be needed in typical use.

con

database connection; used to select correct quoting characters.

Examples

1
2
3
4
5
6
7
8
9
build_sql("SELECT * FROM TABLE")
x <- "TABLE"
build_sql("SELECT * FROM ", x)
build_sql("SELECT * FROM ", ident(x))
build_sql("SELECT * FROM ", sql(x))

# http://xkcd.com/327/
name <- "Robert'); DROP TABLE Students;--"
build_sql("INSERT INTO Students (Name) VALUES (", name, ")")

sctyner/dplyr050 documentation built on May 17, 2019, 2:22 p.m.