dbRunScript {etl}R Documentation

Execute an SQL script

Description

Execute an SQL script

Usage

dbRunScript(conn, script, echo = FALSE, ...)

Arguments

conn

a DBIConnection-class object

script

Either a filename pointing to an SQL script or a character vector of length 1 containing SQL.

echo

print the SQL commands to the output?

...

arguments passed to dbExecute

Details

The SQL script file must be ; delimited.

Value

a list of results from dbExecute for each of the individual SQL statements in script.

Examples

sql <- "SHOW TABLES; SELECT 1+1 as Two;"
sql2 <- system.file("sql", "mtcars.mysql", package = "etl")
sql3 <- "SELECT * FROM user WHERE user = 'mysql';SELECT * FROM user WHERE 't' = 't';"

if (require(RSQLite)) {
  con <- dbConnect(RSQLite::SQLite())
  dbRunScript(con, "SELECT 1+1 as Two; VACUUM; ANALYZE;")
}
## Not run: 
if (require(RMySQL)) {
 con <- dbConnect(RMySQL::MySQL(), default.file = path.expand("~/.my.cnf"),
   group = "client", user = NULL, password = NULL, dbname = "mysql", host = "127.0.0.1")
 dbRunScript(con, script = sql)
 dbRunScript(con, script = sql2)
 dbRunScript(con, script = sql3)
 dbDisconnect(con)
}

## End(Not run)


[Package etl version 0.4.1 Index]