X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Ffunctional.cl;h=e25f01524b90c136a6ebc36017263e51764f34ca;hb=865598033baf78cf3ba9da36a031a85eb18849e0;hp=636215452eb7d836156acfe2a570a2d4789e5ddd;hpb=b53b2149b724a9d7cb33b80d7110d40508c50c20;p=clsql.git diff --git a/sql/functional.cl b/sql/functional.cl index 6362154..e25f015 100644 --- a/sql/functional.cl +++ b/sql/functional.cl @@ -8,7 +8,7 @@ ;;;; ;;;; Copyright (c) 1999-2001 Pierre R. Mai ;;;; -;;;; $Id: functional.cl,v 1.4 2002/05/04 02:43:15 kevin Exp $ +;;;; $Id: functional.cl,v 1.6 2002/05/11 14:31:10 marc.battyani Exp $ ;;;; ;;;; This file is part of CLSQL. ;;;; @@ -84,18 +84,16 @@ where) :database database)))) -(defmacro with-database ((db-var connection-spec - &rest connect-args - &key (pool nil)) - &body body) +(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'. -If pool is t the the connection will be taken from the general pool, -if pool is a conn-pool object the connection will be taken from this pool. -The connection is automatically closed or released to the pool -on exit from the body." - `(let ((,db-var (connect ,connection-spec :pool ,pool ,@connect-args))) - (unwind-protect - (progn - ,@body) - (disconnect :database ,db-var :poool ,pool)))) +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