database is locked in R
r, sql, sqlite
Solution
It seems that you connect several times to the same database without disconnecting. Probably the database goes into a lock if a connection is made to prevent anyone else from editing a database which is already being edited.
Either disconnect after each connect, or simply connect once, perform all the queries, and than finally disconnect.
Problem
In R, i am using the following function,which uses 3 or 4 database operation within that function. But an error message is displaying like this: ``` Error in sqliteExecStatement(conn, statement, ...) : RS-DBI driver: (RS_SQLite_exec: could not execute1: database is locked) ``` What modification i need to make in my code? my code is as follows: ``` library('RSQLite') test <- function(portfolio,date,frame){ lite <- dbDriver("SQLite", max.con = 25) db <- dbConnect(lite, dbname = "portfolioInfo1.db") sql <- paste("SELECT * from ", portfolio," where portDate='", date, "' ", sep = "") res <- dbSendQuery(db, sql) data <- fetch(res) frame1 <- data.frame(portDate=date,frame) lite <- dbDriver("SQLite", max.con = 25) db <- dbConnect(lite, dbname = "portfolioInfo1.db") sql <- paste("delete from ", portfolio," where portDate='", date, "' ", sep = "") res <- dbSendQuery(db, sql) lite <- dbDriver("SQLite", max.con = 25) db <- dbConnect(lite, dbname = "portfolioInfo1.db") dbWriteTable(db,portfolio,frame1,append=TRUE,row.names=FALSE) } tick <- c("AAPL","TH","YHOO") quant <- c("121","1313","131313131") frame <-data.frame(ticker=tick,quantities=quant) #print(frame) test("RUSEG","2006-02-28",frame) ```