fetch-methods              package:DBI              R Documentation

_F_e_t_c_h _r_e_c_o_r_d_s _f_r_o_m _a _p_r_e_v_i_o_u_s_l_y _e_x_e_c_u_t_e_d _q_u_e_r_y

_D_e_s_c_r_i_p_t_i_o_n:

     Fetch records from a previously executed query

_U_s_a_g_e:

       fetch(res, n, ...)

_A_r_g_u_m_e_n_t_s:

     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 typically produced by a call
          to or 'dbSendQuery'. 

       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  of 'n = 0' for fetching the
          defined 'fetch.default.rec' in  the 'dbDriver' invocation. 

    ... : any other database-engine specific arguments. 

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

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

_S_i_d_e _E_f_f_e_c_t_s:

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

_N_o_t_e:

     Make sure you close the result set with 'dbClearResult' as soon as
     you finish retrieving the records you want.

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

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

_E_x_a_m_p_l_e_s:

     ## Not run: 
     # 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)
     ## End(Not run)

