Learn R Programming

gmDatabase (version 0.5.1)

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"))

Value

gmSQLValues

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

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.

Author

K. Gerald van den Boogaart

Details

The functions currently use gmEscapeStrings and are therefore only reliable with RMySQL-Connections.

See Also

gmEscapeStrings

Examples

Run this code
if (FALSE) {
.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")
}

Run the code above in your browser using DataLab