dbNextResult-methods         package:RMySQL         R Documentation

_F_e_t_c_h _N_e_x_t _R_e_s_u_l_t _S_e_t _f_r_o_m _M_u_l_t_i_p_l_e _S_t_a_t_e_m_e_n_t_s _o_r _S_t_o_r_e_d _P_r_o_c_e_d_u_r_e_s

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

     'dbMoreResults' checks whether there are additional result sets
     for processing. 'dbNextResult' fetches the next result set.

_M_e_t_h_o_d_s:

          These MySQL methods provide functionality to sequentially
          extract multiple results produced by SQL scripts or stored
          procedures.

          In the case of stored procedures invoked with 'CALL', the
          first  result set indicates the call status, and output data
          (if any) are return as additional result sets.

     _c_o_n = "_M_y_S_Q_L_C_o_n_n_e_c_t_i_o_n" a MySQL connection object.

_N_o_t_e:

     MySQL supports SQL scripts (a single string with multiple
     statements  terminated by ';') from version 4.1.1 onwards and
     stored procedures  from version 5.0.

     To process SQL scripts on a MySQL connection,  the connection must
     be created using the 'CLIENT_MULTI_STATEMENTS'. In addition, to
     process stored procedures that return one or more result sets, the
     connection must be created using the  'CLIENT_MULTI_RESULTS'
     client flag.

     For simplicity, use 'CLIENT_MULTI_STATEMENTS' for working with
     either SQL scripts or stored procedures.  For more details, read
     on.

     More precisely, to execute multiple statements the connection
     needs  'CLIENT_MULTI_STATEMENTS'; this in turn automatically
     enables  'CLIENT_MULTI_RESULTS' for _fetching_ of multiple output 
     results.  On the other hand, the client flag
     'CLIENT_MULTI_RESULTS' by  itself enables stored procedures to
     return one or more results. See the MySQL documentation in <URL:
     www.mysql.com> for full details.

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

     'MySQL', 'dbConnect', 'dbSendQuery', 'dbHasCompleted', 'fetch',
     'dbCommit', 'dbGetInfo', 'dbReadTable'.

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

     ## Not run: 
     con <- dbConnect(MySQL(), 
               dbname = "rs-dbi", 
               client.flag=CLIENT\_MULTI\_STATEMENTS)
     sql.script <- paste(
        "select * from abc",
        "select * def", 
        collapse = ";")

     rs1 <- dbSendQuery(con, sql.script)
     data1 <- fetch(rs1, n = -1)

     if(dbMoreResults(con)){
        rs2 <- dbNextResult(con)
        ## you could use dbHasCompleted(rs2) to determine whether
        ## rs2 is a select-like that generates output or not.
        data2 <- fetch(rs2, n = -1)   
        }
     ## End(Not run)

