X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=base%2Fdatabase.lisp;h=cc26d7119c517449b603ed41b654adeec3594017;hb=dd0b244d779d96f80e262e02ce4d2f793888b79f;hp=5f00b3867aee1b08c8b23d2eb7b712e23fbfca79;hpb=2c14c425a4a203e03b74b868fdf727ea0d48572a;p=clsql.git diff --git a/base/database.lisp b/base/database.lisp index 5f00b38..cc26d71 100644 --- a/base/database.lisp +++ b/base/database.lisp @@ -176,9 +176,24 @@ error should be signaled if the existing database connection cannot be closed. When non-nil (this is the default value) the connection is closed without error checking. When FORCE is nil, an error is signaled if the database connection has been lost." - ;; TODO: just a placeholder - (declare (ignore database error force))) - + (let ((db (etypecase database + (database database) + ((or string list) + (let ((db (find-database database :errorp nil))) + (when (null db) + (if (and database error) + (error 'clsql-generic-error + :message + (format nil "Unable to find database with connection-spec ~A." database)) + (return-from reconnect nil))) + db))))) + + (when (is-database-open db) + (if force + (ignore-errors (disconnect :database db)) + (disconnect :database db :error nil))) + + (connect (connection-spec db)))) (defun status (&optional full) @@ -231,6 +246,10 @@ of full is NIL." (setq connection-spec (string-to-list-connection-spec connection-spec))) (database-destroy connection-spec database-type)) +(defun list-databases (connection-spec &key database-type) + (when (stringp connection-spec) + (setq connection-spec (string-to-list-connection-spec connection-spec))) + (database-list connection-spec database-type)) (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