dbCommit-methods {RSQLite} | R Documentation |
By default, SQLite is in auto-commit mode. dbBeginTransaction
starts a SQLite transaction and turns auto-commit
off. dbCommit
and dbRollback
commit and rollback the
transaction, respectively and turn auto-commit on.
SQLiteConnection
object, as produced by the function
dbConnect
.
See the Database Interface definition document
DBI.pdf
in the base directory of this package
or
http://stat.bell-labs.com/RS-DBI.
SQLite
,
dbConnect
,
dbSendQuery
,
dbGetQuery
,
fetch
,
dbCommit
,
dbGetInfo
,
dbReadTable
.
drv <- dbDriver("SQLite") tfile <- tempfile() con <- dbConnect(drv, dbname = tfile) data(USArrests) dbWriteTable(con, "arrests", USArrests) dbGetQuery(con, "select count(*) from arrests")[1, ] dbBeginTransaction(con) rs <- dbSendQuery(con, "DELETE from arrests WHERE Murder > 1") do_commit <- if (dbGetInfo(rs)[["rowsAffected"]] > 40) FALSE else TRUE dbClearResult(rs) dbGetQuery(con, "select count(*) from arrests")[1, ] if (!do_commit) dbRollback(con) dbGetQuery(con, "select count(*) from arrests")[1, ] dbBeginTransaction(con) rs <- dbSendQuery(con, "DELETE from arrests WHERE Murder > 5") dbClearResult(rs) dbCommit(con) dbGetQuery(con, "select count(*) from arrests")[1, ] dbDisconnect(con)