The following code sends a query to MySQL and fetch 10000 records each time.
dt <- list()
n <- 1L
res <- dbSendQuery(con, "select * from data")
while (!dbHasCompleted(res)) {
dt[[n]] <- dbFetch(res, 10000)
cat(sprintf("[%s][%d] %d rows fetched\n", as.character(Sys.time()), n, nrow(dt[[n]]))
n <- n + 1L
}
If the query is killed at server side (e.g. done in MySQL Workbench), the while loop runs forever getting zero-row data frame in each fetch and dbHasCompleted does not return TRUE.
Is it a desired behavior or shouldn't it just throw an error and stop everything?
The walk-around is simple, just look at the row number of the latest chunk fetched.