dbCommit-methods: DBMS Transaction Management

Description Methods References See Also Examples

Description

Transaction related commands. Start a transaction, commit or roll back the current transaction in an PostgreSQL connection. dbBegin starts a transaction. dbCommit and dbRollback commit and rollback the transaction, respectively.

Methods

conn

a PostgreSQLConnection object, as produced by the function dbConnect.

...

currently unused.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or https://cran.r-project.org/package=DBI.

See Also

PostgreSQL, dbBegin, dbConnect, dbSendQuery, dbGetQuery, fetch, dbCommit, dbGetInfo, dbReadTable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="postgres")
dbGetQuery(con, "select count(*) from sales")

dbBegin(con)
rs <- dbSendQuery(con, 
      "Delete * from sales as p where p.cost>10")
if(dbGetInfo(rs, what = "rowsAffected") > 250){
  warning("Rolling back transaction")
  dbRollback(con)
}else{
  dbCommit(con)
}

dbGetQuery(con, "select count(*) from sales")
dbDisconnect(con)

## End(Not run)

RPostgreSQL documentation built on May 2, 2019, 8:49 a.m.