From b55c36d4d3835550407db78b1baa76a0bffdc5c1 Mon Sep 17 00:00:00 2001 From: Marc Battyani Date: Fri, 3 May 2002 20:50:18 +0000 Subject: [PATCH] r1901: updated with-database and connect/disconnect functions to work better with the pool. --- sql/functional.cl | 13 ++++++++----- sql/pool.cl | 8 +++++--- sql/sql.cl | 17 ++++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/sql/functional.cl b/sql/functional.cl index 9050b4c..754ad9e 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.3 2002/05/03 20:50:18 marc.battyani Exp $ ;;;; ;;;; This file is part of CLSQL. ;;;; @@ -91,9 +91,12 @@ &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))) +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 + :database-type ,database-type :if-exists ,if-exists))) (unwind-protect (let ((,db-var ,db-var)) ,@body) - (disconnect :database ,db-var :pool pool)))) + (disconnect :database ,db-var)))) diff --git a/sql/pool.cl b/sql/pool.cl index bf790a4..9e94dea 100644 --- a/sql/pool.cl +++ b/sql/pool.cl @@ -7,7 +7,7 @@ ;;;; Programmers: Kevin M. Rosenberg, Marc Battyani ;;;; Date Started: Apr 2002 ;;;; -;;;; $Id: pool.cl,v 1.3 2002/05/01 20:22:16 marc.battyani Exp $ +;;;; $Id: pool.cl,v 1.4 2002/05/03 20:50:18 marc.battyani Exp $ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -43,7 +43,8 @@ (defun clear-conn-pool (pool) (loop for conn across (all-connections pool) - do (disconnect :database conn)) + do (setf (conn-pool conn) nil) + (disconnect :database conn)) (setf (fill-pointer (free-connections pool)) 0) (setf (fill-pointer (all-connections pool)) 0)) @@ -59,7 +60,8 @@ conn-pool)) (defun acquire-from-pool (connection-spec database-type &optional pool) - (unless pool (setf pool (find-or-create-conn-pool connection-spec database-type))) + (unless (typep pool 'conn-pool) + (setf pool (find-or-create-conn-pool connection-spec database-type))) (acquire-from-conn-pool pool)) (defun release-to-pool (database) diff --git a/sql/sql.cl b/sql/sql.cl index 6d2d8bb..310001e 100644 --- a/sql/sql.cl +++ b/sql/sql.cl @@ -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.15 2002/05/03 20:50:18 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,12 +96,15 @@ 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." +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)) + (setq result (acquire-from-pool connection-spec database-type pool)) (if old-db (case if-exists ; (:new @@ -134,11 +137,11 @@ connection-spec. if-exists is currently ignored." 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*)) -- 2.34.1