R/dbRollback_SQLiteConnection.R

Defines functions dbRollback_SQLiteConnection

Documented in dbRollback_SQLiteConnection

#' @rdname sqlite-transaction
#' @usage NULL
dbRollback_SQLiteConnection <- function(conn, .name = NULL, ..., name = NULL) {
  name <- compat_name(name, .name)
  if (is.null(name)) {
    dbExecute(conn, "ROLLBACK")
  } else {
    # The ROLLBACK TO command reverts the state of the database back to what it
    # was just after the corresponding SAVEPOINT. Note that unlike that plain
    # ROLLBACK command (without the TO keyword) the ROLLBACK TO command does not
    # cancel the transaction. Instead of cancelling the transaction, the
    # ROLLBACK TO command restarts the transaction again at the beginning. All
    # intervening SAVEPOINTs are canceled, however.
    name_quoted <- dbQuoteIdentifier(conn, name)
    dbExecute(conn, paste0("ROLLBACK TO ", name_quoted))
    dbExecute(conn, paste0("RELEASE SAVEPOINT ", name_quoted))
  }
  invisible(TRUE)
}
#' @rdname sqlite-transaction
#' @export
setMethod("dbRollback", "SQLiteConnection", dbRollback_SQLiteConnection)

Try the RSQLite package in your browser

Any scripts or data that you put into this service are public.

RSQLite documentation built on May 29, 2024, 3:30 a.m.