r1990: small corrections
authorMarc Battyani <marc.battyani@fractalconcept.com>
Sat, 11 May 2002 14:31:10 +0000 (14:31 +0000)
committerMarc Battyani <marc.battyani@fractalconcept.com>
Sat, 11 May 2002 14:31:10 +0000 (14:31 +0000)
sql/functional.cl
sql/sql.cl

index fdb8cb8220518565526e524c000f6892cb897088..e25f01524b90c136a6ebc36017263e51764f34ca 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.6 2002/05/11 14:31:10 marc.battyani 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
index 310001eb221defd1860adb513c293d640fd3ff81..ed18c0b28a33c4ee0e65e38f95eab5f6a7a9c6f8 100644 (file)
@@ -8,7 +8,7 @@
 ;;;;                 Original code by Pierre R. Mai 
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: sql.cl,v 1.15 2002/05/03 20:50:18 marc.battyani Exp $
+;;;; $Id: sql.cl,v 1.16 2002/05/11 14:31:10 marc.battyani Exp $
 ;;;;
 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
@@ -100,22 +100,22 @@ connection-spec.  if-exists is currently ignored.
 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.
 "
-  (let* ((db-name (database-name-from-spec connection-spec database-type))
-        (old-db (unless (eq if-exists :new) (find-database db-name nil)))
-        (result nil))
-    (if pool
-       (setq result (acquire-from-pool connection-spec database-type pool))
+  (if pool
+    (acquire-from-pool connection-spec database-type pool)
+    (let* ((db-name (database-name-from-spec connection-spec database-type))
+          (old-db (unless (eq if-exists :new) (find-database db-name nil)))
+          (result nil))
       (if old-db
-         (case if-exists
+       (case if-exists
 ;          (:new
 ;           (setq result
 ;             (database-connect connection-spec database-type)))
-           (:warn-new
-            (setq result
-              (database-connect connection-spec database-type))
-            (warn 'clsql-exists-warning :old-db old-db :new-db result))
-           (:error
-            (restart-case
+         (:warn-new
+          (setq result
+                (database-connect connection-spec database-type))
+          (warn 'clsql-exists-warning :old-db old-db :new-db result))
+         (:error
+          (restart-case
                 (error 'clsql-exists-error :old-db old-db)
               (create-new ()
                   :report "Create a new connection."
@@ -124,17 +124,17 @@ if pool is a conn-pool object the connection will be taken from this pool.
               (use-old ()
                   :report "Use the existing connection."
                 (setq result old-db))))
-           (:warn-old
-            (setq result old-db)
-            (warn 'clsql-exists-warning :old-db old-db :new-db old-db))
-           (:old
-            (setq result old-db)))
+         (:warn-old
+          (setq result old-db)
+          (warn 'clsql-exists-warning :old-db old-db :new-db old-db))
+         (:old
+          (setq result old-db)))
        (setq result
-         (database-connect connection-spec database-type))))
-    (when result
-      (pushnew result *connected-databases*)
-      (setq *default-database* result)
-      result)))
+             (database-connect connection-spec database-type)))
+      (when result
+       (pushnew result *connected-databases*)
+       (setq *default-database* result)
+       result))))
 
 
 (defun disconnect (&key (database *default-database*))