gmSQL: Provide an R representation of SQL

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

gmSQL provides an R representation of SQL, which can be used to construct a complex hierachy of joins and select statements.

Usage

1
2
3

Arguments

.

For gmSQL an unquote expression to be interpreted as the R representation of SQL described under details.

expr

The quoted version of such an expression.

env

The environment holding the variables used in the expression.

table

a character string giving the name of the SQL table denoted.

as

the alias of the table in the SQL expression

Details

These commands allow to construct a representation of a small subset of SQL statements by R language objects. The following (derived) table value statements are supported

Special environments SQLenv and SQL2SQLenv are used in order to prevent code injection.

Value

For gmSQL and gmSQLTable, a call representing the intended SQL expression as R expression. For gmSQL2SQL a character string holding the corresponding SQL expression.

Author(s)

K. Gerald van den Boogaart, S. Matos Camacho

References

http://dev.mysql.com/doc/refman/5.7/en

See Also

dbSendQuery

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
tabA <- gmSQLTable("A")
tabB <- gmSQLTable("B")
ennv <- new.env(parent=SQLenv)
assign("tabA", tabA, ennv)
assign("tabB", tabB, ennv)
AB <- gmSQL(join(tabA,tabB,on=tabA$id==tabB$refID), env=ennv)
AB
gmSQL2SQL(tabA)
gmSQL2SQL(tabB)
gmSQL2SQL(AB)
legalvalues <- 1:3
assign("AB", AB, ennv)
assign("legalvalues", legalvalues, ennv)
sAB <- gmSQL(select(what=list(x=1,y=tabA$y*tabB$y),
                    from=AB,
                    where=Call("log",tabB$othervalue)<=17 &&
                          IN(tabA$inte,c(legalvalues)),
                    as=NULL), env=ennv)

cat(gmSQL2SQL(sAB))

gmDatabase documentation built on May 2, 2019, 9:31 a.m.

Related to gmSQL in gmDatabase...