dbNextResult: Fetch next result set from an SQL script or stored procedure...

Description Usage Arguments Value Examples

Description

SQL scripts (i.e., multiple SQL statements separated by ';') and stored procedures oftentimes generate multiple result sets. These generic functions provide a means to process them sequentially. dbNextResult fetches the next result from the sequence of pending results sets; dbMoreResults returns a logical to indicate whether there are additional results to process.

Usage

1
2
3
4
5
6
7
8
9
dbNextResult(con, ...)

## S4 method for signature 'MySQLConnection'
dbNextResult(con, ...)

dbMoreResults(con, ...)

## S4 method for signature 'MySQLConnection'
dbMoreResults(con, ...)

Arguments

con

a connection object (see dbConnect).

...

any additional arguments to be passed to the dispatched method

Value

dbNextResult returns a result set or NULL.

dbMoreResults returns a logical specifying whether or not there are additional result sets to process in the connection.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
if (mysqlHasDefault()) {
con <- dbConnect(RMySQL::MySQL(), dbname = "test", client.flag = CLIENT_MULTI_STATEMENTS)
dbWriteTable(con, "mtcars", datasets::mtcars, overwrite = TRUE)

sql <- "SELECT cyl FROM mtcars LIMIT 5; SELECT vs FROM mtcars LIMIT 5"
rs1 <- dbSendQuery(con, sql)
dbFetch(rs1, n = -1)

if (dbMoreResults(con)) {
   rs2 <- dbNextResult(con)
   dbFetch(rs2, n = -1)
}

dbClearResult(rs1)
dbClearResult(rs2)
dbRemoveTable(con, "mtcars")
dbDisconnect(con)
}

Example output

Loading required package: DBI
Could not initialise default MySQL database. If MySQL is running
check that you have a ~/.my.cnf file that contains a [rs-dbi] section
describing how to connect to a test database.

RMySQL documentation built on June 22, 2021, 5:08 p.m.

Related to dbNextResult in RMySQL...