Learn R Programming

gmDatabase (version 0.5.0)

gmSQLValues: Format vector in parenthesis and SQL quote it

Description

Formats values for use in SQL statements

Usage

gmSQLValues(v,quote=TRUE,db=getOption("gmDB"))

Arguments

v
The values to be converted, could be dataframe, numeric vector or something convertable to a character vector.
quote
Logocical value defining if the given values shall be quoted.
db
The database connection for which the transformation shall be done. Currently only mysql is supported.

Value

A single string containing an SQL representation of the vector for use with the IN operator.

Details

The functions currently use dbEscapeStrings and are therefor only reliable with RMySQL-Connections.

See Also

gmEscapeStrings

Examples

Run this code
## Not run: 
# .gmDB <- dbConnect(...)
# complexString <- "He said: \"I\'m going to the circus\"\n"
# cat(complexString)
# gmEscapeStrings(complexString)
# cat(gmEscapeStrings(complexString),"\n")
# cat(gmSQLValues(complexString),"\n")
# myfactor <- factor(c("a","a","b"))
# cat(gmSQLValues(myfactor),"\n")
# num <- 1:3
# cat(gmSQLValues(num),"\n")
# 
# X <- data.frame(string=rep(complexString,3),fac=myfactor,x=num)
# cat(gmSQLValues(X),"\n")
# ## End(Not run)

Run the code above in your browser using DataLab