Suppose you're trying to do a typical insert-or-update loop with RSQLite. I would expect the following to work:
library(DBI)
testdb <- dbConnect(RSQLite::SQLite(), "test.sqlite")
dbExecute(testdb, "CREATE TABLE spray_count (spray TEXT, count INTEGER)")
urs <- dbSendStatement(testdb, "UPDATE spray_count SET count = count + :count WHERE spray = :spray")
irs <- dbSendStatement(testdb, "INSERT INTO spray_count VALUES (:spray, :count)")
for (i in 1:nrow(InsectSprays)) {
print(paste("update", i))
dbBind(urs, InsectSprays[i,])
if (!dbGetRowsAffected(urs)) {
print(paste("insert", i))
dbBind(irs, InsectSprays[i,])
}
}
But it does not:
[1] "update 1"
Error in rsqlite_bind_rows(res@ptr, params) :
external pointer is not valid
In addition: Warning message:
Closing open result set, pending rows
Basically it seems that you can have only one prepared statement at a time, and creating a second one somehow invalidates the first. Am I missing something or is this a limitation of DBI and/or RSQLite? I have DBI v0.6-1 and RSQLite v1.1-2.