r10969: 04 Jul 2006 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / db-postgresql / postgresql-sql.lisp
index 9b4e2503f0b5ac415a64147cad594385c20b6283..d5a13f29befdbbc5eb86c7a5737e2a98e41f9954 100644 (file)
        (declare (type pgsql-conn-def connection))
        (when (not (eq (PQstatus connection) 
                       pgsql-conn-status-type#connection-ok))
-         (error 'sql-connection-error
-                :database-type database-type
-                :connection-spec connection-spec
-                :error-id (PQstatus connection)
-                :message (tidy-error-message 
-                          (PQerrorMessage connection))))
+          (let ((pqstatus (PQstatus connection))
+                (pqmessage (tidy-error-message (PQerrorMessage connection))))
+            (PQfinish connection)
+            (error 'sql-connection-error
+                   :database-type database-type
+                   :connection-spec connection-spec
+                   :error-id pqstatus
+                   :message  pqmessage)))
        (make-instance 'postgresql-database
                       :name (database-name-from-spec connection-spec
                                                      database-type)