在 R 中,我正在使用以下函数,该函数在该函数中使用 3 或 4 个数据库操作。但是显示如下错误消息:
Error in sqliteExecStatement(conn, statement, ...) :
RS-DBI driver: (RS_SQLite_exec: could not execute1: database is locked)
我需要在我的代码中进行哪些修改?我的代码如下:
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)