r2913: *** empty log message ***
[clsql.git] / sql / functional.cl
index fdb8cb8220518565526e524c000f6892cb897088..e283e5d1191b5c7de3dae5b8a094c1cb3048ea10 100644 (file)
@@ -8,7 +8,7 @@
 ;;;;
 ;;;; Copyright (c) 1999-2001 Pierre R. Mai
 ;;;;
-;;;; $Id: functional.cl,v 1.5 2002/05/04 09:27:12 marc.battyani Exp $
+;;;; $Id: functional.cl,v 1.8 2002/09/17 17:16:43 kevin Exp $
 ;;;;
 ;;;; This file is part of CLSQL. 
 ;;;;
   "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 or released to the pool 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))))
+  (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