To retrieve results a chunk at a time, use dbSendQuery,
dbFetch, then dbClearResult. Alternatively, if you want all the
results (and they'll fit in memory) use dbGetQuery which sends,
fetches and clears for you.
Usage
# S4 method for class 'MySQLResult,numeric'
dbFetch(res, n = -1, ...)
# S4 method for class 'MySQLResult,numeric'
fetch(res, n = -1, ...)
# S4 method for class 'MySQLResult,missing'
dbFetch(res, n = -1, ...)
# S4 method for class 'MySQLResult,missing'
fetch(res, n = -1, ...)
# S4 method for class 'MySQLConnection,character'
dbSendQuery(conn, statement, ...)
# S4 method for class 'MySQLResult'
dbClearResult(res, ...)
# S4 method for class 'MySQLResult'
dbGetInfo(dbObj, what = "", ...)
# S4 method for class 'MySQLResult'
dbGetStatement(res, ...)
# S4 method for class 'MySQLResult,missing'
dbListFields(conn, name, ...)Arguments
- res, dbObj
A
MySQLResultobject.- n
maximum number of records to retrieve per fetch. Use
-1to retrieve all pending records; use0for to fetch the default number of rows as defined inMySQL- ...
Unused. Needed for compatibility with generic.
- conn
an
MySQLConnectionobject.- statement
a character vector of length one specifying the SQL statement that should be executed. Only a single SQL statment should be provided.
- what
optional
- name
Table name.
Examples
if (mysqlHasDefault()) {
con <- dbConnect(RMySQL::MySQL(), dbname = "test")
dbWriteTable(con, "arrests", datasets::USArrests, overwrite = TRUE)
# Run query to get results as dataframe
dbGetQuery(con, "SELECT * FROM arrests limit 3")
# Send query to pull requests in batches
res <- dbSendQuery(con, "SELECT * FROM arrests")
data <- dbFetch(res, n = 2)
data
dbHasCompleted(res)
dbListResults(con)
dbClearResult(res)
dbRemoveTable(con, "arrests")
dbDisconnect(con)
}
#> Could not initialise default MySQL database. If MySQL is running
#> check that you have a ~/.my.cnf file that contains a [rs-dbi] section
#> describing how to connect to a test database.