RMySQL dbGetQuery () inside a function leaves pending results

My function contained in a larger function uses dbConnect(), dbGetQuery()and dbDisconnect().

When a function error fails, I fix it and try to restart it. I can not repeat it because I get:  Error in mysqlCloseConnection(conn, ...) : connection has pending rows (close open results set first)

(Note 1: I do not use dbSendQuery()+ fetch(), simply dbGetQuery(), so this is a strange error in itself.)
(Note 2: Errors DO NOT occur in the code RMySQL, they occur in other parts of the R-code.)

Unsuccessful solution 1: dbClearResult(dbListResults(myconnection)[[1]])does not work, because it was created inside the function environment myconnection.

Unsuccessful solution 2: lapply( dbListConnections( dbDriver( drv = "MySQL")), dbDisconnect)errors with the same error message "deferred lines" above.

My only solution now is to kill R and start over. However, I know that the connection still exists in the SQL database (because my boss tells me so), so I am looking for a suitable solution to close the result / connection.

Thanks for any help.

+4
source share
1 answer

I had a similar problem, so it could help other people in the future ...

pull<- dbSendQuery(con, statement...)
df2 <- fetch(pull, n = -1)
> dbHasCompleted(pull)
[1] TRUE
> dbDisconnect(con)
[1] TRUE
+2
source

Source: https://habr.com/ru/post/1534561/


All Articles