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.
build_sql(..., .env = parent.frame(), con = sql_current_con())
the environment in which to evalute the arguments. Should not be needed in typical use.
database connection; used to select correct quoting characters.
build_sql("SELECT * FROM TABLE")#> <SQL> SELECT * FROM TABLEx <- "TABLE" build_sql("SELECT * FROM ", x)#> <SQL> SELECT * FROM 'TABLE'build_sql("SELECT * FROM ", ident(x))#> <SQL> SELECT * FROM "TABLE"build_sql("SELECT * FROM ", sql(x))#> <SQL> SELECT * FROM TABLE# http://xkcd.com/327/ name <- "Robert'); DROP TABLE Students;--" build_sql("INSERT INTO Students (Name) VALUES (", name, ")")#> <SQL> INSERT INTO Students (Name) VALUES ('Robert''); DROP TABLE Students;--')