
n
elements (rows) from the result set and return them
as a data.frame.dbFetch(res, n = -1, ...)fetch(res, n = -1, ...)
DBIResult
.n = -1
to retrieve all pending records. Some implementations may recognize other
special values.fetch
is provided for compatibility with older DBI clients - for all
new code you are strongly encouraged to use dbFetch
. The default
method for dbFetch
calls fetch
so that it is compatible with
existing code. Implementors should provide methods for both fetch
and
dbFetch
until fetch
is deprecated in 2015.dbClearResult
as soon as you
finish retrieving the records you want.Other DBIResult generics: dbClearResult
;
dbColumnInfo
; dbGetRowCount
,
dbGetRowCount,DBIResult-method
;
dbGetRowsAffected
,
dbGetRowsAffected,DBIResult-method
;
dbGetStatement
,
dbGetStatement,DBIResult-method
;
dbHasCompleted
,
dbHasCompleted,DBIResult-method
if (!require("RSQLite")) {
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
# Fetch all results
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)
# Fetch in chunks
res <- dbSendQuery(con, "SELECT * FROM mtcars")
while (!dbHasCompleted(res)) {
chunk <- fetch(res, 10)
print(nrow(chunk))
}
dbClearResult(res)
dbDisconnect(con)
}
Run the code above in your browser using DataLab