Skip to content

Commit

Permalink
fixes for upcoming RSQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg committed Sep 22, 2016
1 parent 8cbba73 commit 78235a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
DBI,
digest,
parallel,
RSQLite (>= 1.0.0),
RSQLite (>= 1.0.9011),
sendmailR,
stats,
stringi (>= 0.4-1),
Expand Down
4 changes: 2 additions & 2 deletions R/batchMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ batchMap = function(reg, fun, ..., more.args = list(), use.names = FALSE) {
}

# add jobs to DB
n = dbAddData(reg, "job_def", data = data.frame(fun_id = fun.id, pars = pars, jobname = jobname))
n = dbAddData(reg, "job_def", data = data.frame(fun_id = fun.id, pars = pars, jobname = jobname, stringsAsFactors = FALSE))
job.def.ids = dbGetLastAddedIds(reg, "job_def", "job_def_id", n)
n = dbAddData(reg, "job_status", data = data.frame(job_def_id = job.def.ids, seed = seeds))
n = dbAddData(reg, "job_status", data = data.frame(job_def_id = job.def.ids, seed = seeds, stringsAsFactors = FALSE))
job.ids = dbGetLastAddedIds(reg, "job_status", "job_id", n)

# we can only create the dir after we have obtained the ids from the DB
Expand Down
18 changes: 13 additions & 5 deletions R/database.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,22 @@ dbAddData = function(reg, tab, data) {
collapse(colnames(data)), collapse(rep.int("?", ncol(data))))
con = dbConnectToJobsDB(reg, flags = "rw")
on.exit(dbDisconnect(con))

dbBegin(con)
ok = try(dbGetPreparedQuery(con, query, bind.data = data))
if(is.error(ok)) {
dbRollback(con)
stopf("Error in dbAddData: %s", as.character(ok))
res = dbSendQuery(con, query)
for (i in seq_row(data)) {
row = unname(as.list(data[i, ]))
dbBind(res, row)
ok = try(dbFetch(res))
if(is.error(ok)) {
dbClearResult(res)
dbRollback(con)
stopf("Error in dbAddData: %s", as.character(ok))
}
}

dbClearResult(res)
dbCommit(con)

as.integer(dbGetQuery(con, "SELECT total_changes()"))
}

Expand Down

0 comments on commit 78235a2

Please sign in to comment.