5

I need to check if my res from dbSendQuery() is over.

My code is like this:

db <- dbConnect(drv=SQLite(),flags=SQLITE_RW,dbname="db.sqlite",synchronous = "off")
dbBegin(db)
res <- dbSendQuery(db,"Update Operation SET Name = 'teste' where Id = 1")
if("my SendQuery is over"){
  dbClearResult(res)
  dbCommit(db)
  dbDisconnect(db)
}

I need to know when it is over to send this to commit and then disconnect.

UPDATE 1 Im my sistem, for this example above can happen with more than 1 users simultaneous. Then, when the first connection in db is over, i need to finish him requisition and provide to the other connection the possibility to write your query.

  • I just saw your edit, didn't receive a notification. -- What happens when two users (processes? threads?) access the database simultaneously with this code? – krlmlr Oct 04 '19 at 18:52
  • @krlmr right now, when two user's use the db simultaneous, the second have a erro saying "data base is locked" because the first is using, and i can't check to waiting the first disconnect. – Walercy Rodrigues de Oliveira Oct 04 '19 at 21:07

1 Answers1

3

dbSendQuery() always awaits completion. You can double-check by calling dbGetRowsAffected(res) .

For SQL statements that are run for the side effect and do not return a value, dbSendStatement() is preferred.

The synchronous = "off" argument to dbConnect() is a misnomer, this defines when and how the data is written to disk; no multi-threading is involved here.

krlmlr
  • 25,056
  • 14
  • 120
  • 217