Fetch records from a previously executed query
Fetch records from a previously executed query.
fetch(res, n, ...)
- a result set object (one whose class extends
DBIResult). This object needs to be the result of a statement that produces output, such as SQL's
SELECT-like statement, this object
- maximum number of records to retrieve per fetch.
n = -1to retrieve all pending records. Some implementations may recognize other special values.
- any other database-engine specific arguments.
See the notes for the various database server implementations.
- a data.frame with as many rows as records were fetched and as many columns as fields in the result set.
Make sure you close the result set with
as soon as you finish retrieving the records you want.
As the R/Splus client fetches records the remote database server updates its cursor accordingly.
See the Database Interface definition document
DBI.pdf in the base directory of this package
# Run an SQL statement by creating first a resultSet object drv <- dbDriver("ODBC") con <- dbConnect(drv, ...) res <- dbSendQuery(con, statement = paste( "SELECT w.laser_id, w.wavelength, p.cut_off", "FROM WL w, PURGE P", "WHERE w.laser_id = p.laser_id", "ORDER BY w.laser_id")) # we now fetch the first 100 records from the resultSet into a data.frame data1 <- fetch(res, n = 100) dim(data1) dbHasCompleted(res) # let's get all remaining records data2 <- fetch(res, n = -1)