;;;;
;;;; Copyright (c) 1999-2001 Pierre R. Mai
;;;;
-;;;; $Id: functional.cl,v 1.1 2002/03/23 14:04:54 kevin Exp $
+;;;; $Id: functional.cl,v 1.6 2002/05/11 14:31:10 marc.battyani Exp $
;;;;
;;;; This file is part of CLSQL.
;;;;
(defmacro with-database ((db-var connection-spec &rest connect-args) &body body)
"Evaluate the 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 on exit from the body."
- `(let ((,db-var (connect ,connection-spec ,@connect-args)))
- (unwind-protect
- (let ((,db-var ,db-var)) ,@body)
- (disconnect :database ,db-var))))
+The connection is automatically closed or released to the pool on exit from the body."
+ (let ((result (gensym "result-")))
+ (unless db-var (setf db-var '*default-database*))
+ `(let ((,db-var (connect ,connection-spec ,@connect-args))
+ (,result nil))
+ (unwind-protect
+ (let ((,db-var ,db-var))
+ (setf ,result (progn ,@body)))
+ (disconnect :database ,db-var))
+ ,result)))
\ No newline at end of file