Next Previous Up Top Contents Index

16 The SQL Package

with-transaction

Macro

Summary

Performs a body of code within a transaction for a database.
Package

sql

Signature

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

Arguments

database

A database type.

body

A set of Lisp expressions.

Values

result

The value returned by body.

Description

The macrowith-transaction performs body within a transaction for database (which defaults to*default-database*). The transaction is committed if the body finishes successfully, otherwise the database is rolled back.
Example

The following example shows how to usewith-transaction to insert a new record, updates the department number of employes from 40 to 50, and removes employees whose salary is higher than 300,000. If an error occurs anywhere in the body and anabort orthrow is executed, none of the updates are committed.
(with-transaction
 (insert-record :into [emp]
              :attributes '(x y z)
               :values '(a b c))
 (update-records [emp]
    :attributes [dept]
    :values 50
    :where [= [dept] 40])
 (delete-records :from [emp]
    :where [> [salary] 300000]))

See also

commit
rollback


LispWorks Reference Manual - 15 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker