Name

WITH-TRANSACTION — Execute a body of code within a transaction.Macro

Syntax

      with-transaction &key database &rest body => result

Arguments and Values

database

A database object. This will default to the value of *default-database*.

body

A body of Lisp code.

result

The result of executing body.

Description

Starts a transaction in the database specified by database, which is *default-database* by default, and executes body within that transaction. If body aborts or throws, database is rolled back and otherwise the transaction is committed.

Examples

(in-transaction-p)
=> NIL
(select [email] :from [employee] :where [= [emplid] 1] :flatp t :field-names nil)
=> ("lenin@soviet.org")
(with-transaction () 
   (update-records [employee] 
                   :av-pairs '((email "lenin-nospam@soviet.org"))
                   :where [= [emplid] 1]))
=> NIL
(select [email] :from [employee] :where [= [emplid] 1] :flatp t :field-names nil)
=> ("lenin-nospam@soviet.org")
(in-transaction-p)
=> NIL
      

Side Effects

Changes specified in body may be made to the underlying database if body completes successfully.

Affected by

None.

Exceptional Situations

Signals an error of type sql-database-error if database is not a database object.

See Also

start-transaction
commit
rollback
add-transaction-commit-hook
add-transaction-rollback-hook

Notes

None.