dbRunScript | R Documentation |
Execute an SQL script
dbRunScript(conn, script, echo = FALSE, ...)
conn |
a |
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 |
The SQL script file must be ;
delimited.
a list of results from dbExecute
for each of the individual
SQL statements in script
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.