transact_sql: Perform SQL operations within a transaction

View source: R/transact_sql.R

transact_sqlR Documentation

Perform SQL operations within a transaction

Description

A transaction allows SQL operations to be batched, such that either all operations are applied or none are. In the jargon, the entire transaction is either committed or rolled back. This is useful to ensure database consistency, without the risk of partial changes caused by unexpected errors in the middle of an operation.

Usage

transact_sql(fun, ...)

break_sql()

Arguments

fun

A function which contains all desired SQL operations

...

Arguments passed to fun()

Details

transact_sql() calls fun() within a transaction. There are three possible outcomes:

  • if the function returns successfully, then the transaction is committed;

  • if an error is thrown, then the transaction is rolled back and the error is propagated so that it may be handled elsewhere;

  • if break_sql() is called withn fun(), then fun() is interrupted and the transaction is rolled back, but no error is thrown and the program may proceed as normal.

If break_sql() is called outside of a function passed to transact_sql(), it will throw an error.

Value

Returns the value returned by fun(), or NULL if break_sql() was called.


pnacht/simplysql documentation built on Sept. 5, 2024, 8:46 p.m.