transactions: DBMS Transaction Management

Description Usage Arguments Examples

Description

Commits or roll backs the current transaction in an MySQL connection. Note that in MySQL DDL statements (e.g. CREATE TABLE) can not be rolled back.

Usage

1
2
3
4
5
6
7
8
## S4 method for signature 'MySQLConnection'
dbCommit(conn, ...)

## S4 method for signature 'MySQLConnection'
dbBegin(conn, ...)

## S4 method for signature 'MySQLConnection'
dbRollback(conn, ...)

Arguments

conn

a MySQLConnection object, as produced by dbConnect.

...

Unused.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
if (mysqlHasDefault()) {
con <- dbConnect(RMySQL::MySQL(), dbname = "test")
df <- data.frame(id = 1:5)

dbWriteTable(con, "df", df)
dbBegin(con)
dbGetQuery(con, "UPDATE df SET id = id * 10")
dbGetQuery(con, "SELECT id FROM df")
dbRollback(con)

dbGetQuery(con, "SELECT id FROM df")

dbRemoveTable(con, "df")
dbDisconnect(con)
}

Example output

Loading required package: DBI
Could not initialise default MySQL database. If MySQL is running
check that you have a ~/.my.cnf file that contains a [rs-dbi] section
describing how to connect to a test database.

RMySQL documentation built on June 22, 2021, 5:08 p.m.

Related to transactions in RMySQL...