r2006: debian
[clsql.git] / sql / sql.cl
index 6d2d8bb1a8b0478b35ff640d931a658824c88248..ed18c0b28a33c4ee0e65e38f95eab5f6a7a9c6f8 100644 (file)
@@ -8,7 +8,7 @@
 ;;;;                 Original code by Pierre R. Mai 
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: sql.cl,v 1.14 2002/05/01 20:22:16 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
@@ -96,23 +96,26 @@ initialized, as indicated by `*initialized-database-types*'."
                (database-type *default-database-type*)
                (pool nil))
   "Connects to a database of the given database-type, using the type-specific
-connection-spec.  if-exists is currently ignored."
-  (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))
+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.
+"
+  (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."
@@ -121,24 +124,24 @@ connection-spec.  if-exists is currently ignored."
               (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*)
-                  (pool nil))
+(defun disconnect (&key (database *default-database*))
   "Closes the connection to database. Resets *default-database* if that
-database was disconnected and only one other connection exists."
-  (if pool
+database was disconnected and only one other connection exists.
+if the database is from a pool it will be released to this pool."
+  (if (conn-pool database)
       (release-to-pool database)
     (when (database-disconnect database)
       (setq *connected-databases* (delete database *connected-databases*))