sql: SQL escaping.

Description Usage Arguments Examples

View source: R/sql-escape.r

Description

These functions are critical when writing functions that translate R functions to sql functions. Typically a conversion function should escape all it's inputs and return an sql object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sql(...)

ident(...)

is.sql(x)

is.ident(x)

escape(x, parens = NA, collapse = " ", con = NULL)

sql_vector(x, parens = NA, collapse = " ", con = NULL)

Arguments

...

Character vectors that will be combined into a single SQL expression. ident flags its input as a identifier, to ensure that it gets the correct quoting.

x

An object to escape. Existing sql vectors will be left as is, character vectors are escaped with single quotes, numeric vectors have trailing .0 added if they're whole numbers, identifiers are escaped with double quotes.

parens, collapse

Controls behaviour when multiple values are supplied. parens should be a logical flag, or if NA, will wrap in parens if length > 1.

Default behaviour: lists are always wrapped in parens and separated by commas, identifiers are separated by commas and never wrapped, atomic vectors are separated by spaces and wrapped in parens if needed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Doubles vs. integers
escape(1:5)
escape(c(1, 5.4))

# String vs known sql vs. sql identifier
escape("X")
escape(sql("X"))
escape(ident("X"))

# Escaping is idempotent
escape("X")
escape(escape("X"))
escape(escape(escape("X")))

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