RSQLite
RSQLite copied to clipboard
`dbFetch()` gives confusing warning when used with `dbSendStatement()`
Calling dbFetch() on a result of dbSendStatement() gives a confusing warning, telling you to use dbSendStatement():
library(DBI)
fetch_bound_statement <- function(drv) {
con <- dbConnect(drv, ":memory:")
on.exit(dbDisconnect(con), add = TRUE)
dbExecute(con, "CREATE TABLE foo (bar TEXT)")
res <- dbSendStatement(con, "INSERT INTO foo (bar) VALUES (?)")
on.exit(dbClearResult(res), add = TRUE, after = FALSE)
dbBind(res, list("baz"))
dbFetch(res) # <- Should be dbGetRowsAffected()
}
fetch_bound_statement(RSQLite::SQLite())
#> Warning in result_fetch(res@ptr, n = n): SQL statements must be issued with
#> dbExecute() or dbSendStatement() instead of dbGetQuery() or dbSendQuery().
#> data frame with 0 columns and 0 rows
The duckdb driver gives a slightly different warning which got me on track in the end:
fetch_bound_statement(duckdb::duckdb())
#> Warning in dbFetch(res): Should not call dbFetch() on results that do not come
#> from SELECT, got INSERT
#> data frame with 0 columns and 0 rows
Ideally I’d like to hear something like “use dbGetRowsAffected() instead”.