DBI (version 0.1-10)

fetch-methods: Fetch records from a previously executed query

Description

Fetch records from a previously executed query

Usage

fetch(res, n, ...)

Arguments

res
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 or SELECT-like statement, this object res is ty
n
maximum number of records to retrieve per fetch. Use n = -1 to retrieve all pending records. Some implementations may recognize other special values, e.g., RMySQL, ROracle, and RSQLite use a value
...
any other database-engine specific arguments.

Value

  • a data.frame with as many rows as records were fetched and as many columns as fields in the result set.

Side Effects

As the R/S-Plus client fetches records the remote database server updates its cursor accordingly.

Details

How the actual fetching is done is implementation-dependent. Some implementations may leave the result in the DBMS and bring chunks of size n to prevent exhausting the R/S-Plus memory, but there may be a performance penalty; other implementations may copy the entire result set to the a memory space under the driver's control; others may yet return the entire result set directly to R/S-Plus. See the individual drivers' documentation.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or http://developer.r-project.org/db.

See Also

dbConnect, dbSendQuery, dbGetQuery, dbClearResult, dbCommit, dbGetInfo, dbReadTable.

Examples

Run this code
# Run an SQL statement by creating first a resultSet object
drv <- dbDriver("Oracle")
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)

Run the code above in your browser using DataCamp Workspace