X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Ffunctional.cl;h=e283e5d1191b5c7de3dae5b8a094c1cb3048ea10;hp=9050b4cd81b0532b7d33e34432e4c7a808027348;hb=998937376fa6f9ce29bd3c7954fb0ebca91c37d7;hpb=a01be1182a7df36a329ee6384e8e403adb2ed9b1 diff --git a/sql/functional.cl b/sql/functional.cl index 9050b4c..e283e5d 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.2 2002/05/03 18:17:50 kevin Exp $ +;;;; $Id: functional.cl,v 1.8 2002/09/17 17:16:43 kevin Exp $ ;;;; ;;;; This file is part of CLSQL. ;;;; @@ -84,16 +84,16 @@ where) :database database)))) -(defmacro with-database ((db-var connection-spec - &key (if-exists *connect-if-exists*) - (database-type *default-database-type*) - (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'. -The connection is automatically closed on exit from the body." - `(let ((,db-var (connect ,connection-spec :pool pool - :database-type database-type :if-exists if-exists))) - (unwind-protect - (let ((,db-var ,db-var)) ,@body) - (disconnect :database ,db-var :pool 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