Name

WITH-DATABASE — Execute a body of code with a variable bound to a specified database object.Macro

Syntax

      with-database db-var connection-spec &rest connect-args &body body => result

Arguments and Values

db-var

A variable which is bound to the specified database.

connection-spec

A vendor specific connection specification supplied as a list or as a string.

connect-args

Other optional arguments to connect. This macro use a value of NIL for connect's make-default key, This is in contrast to to the connect function which has a default value of T for make-default.

body

A Lisp code body.

result

Determined by the result of executing the last expression in body.

Description

Evaluate body in an environment, where db-var is bound to the database connection given by connection-spec and connect-args. The connection is automatically closed or released to the pool on exit from the body.

Examples

(connected-databases)
=> NIL
(with-database (db '(":memory:") :database-type :sqlite 
                :make-default nil)
  (database-name db))
=> ":memory:"
(connected-databases)
=> NIL
      

Side Effects

See connect and disconnect.

Affected by

See connect and disconnect.

Exceptional Situations

See connect and disconnect.

See Also

connect
disconnect
disconnect-pooled
with-default-database

Notes

with-database is a CLSQL extension.