r10922: 03 May 2006 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / sql / conditions.lisp
index dc48d2fc1201a1da10ad512041b0515621aa2975..5e805e172e11cc3464eafe0e261e92094cafec86 100644 (file)
 (in-package #:clsql-sys)
 
 (defvar *backend-warning-behavior* :warn
-  "Action to perform on warning messages from backend. Default is to :warn. May also be
-set to :error to signal an error or :ignore/nil to silently ignore the warning.")
+  "Action to perform on warning messages from backend. Default is
+to :warn. May also be set to :error to signal an error
+or :ignore/nil to silently ignore the warning.")
 
 ;;; CommonSQL-compatible conditions
  
 (define-condition sql-condition ()
   ())
 
-(define-condition sql-error (simple-error)
+(define-condition sql-error (simple-error sql-condition)
   ())
 
 (define-condition sql-database-error (sql-error)
@@ -42,10 +43,8 @@ set to :error to signal an error or :ignore/nil to silently ignore the warning."
                     :initform nil
                     :reader sql-error-database))
   (:report (lambda (c stream)
-            (format stream "A database error occurred~A: ~A / ~A~%  ~A"
-                    (if (sql-error-database c)
-                        (format nil " on database ~A" (sql-error-database c))
-                        "")
+            (format stream "A database error occurred~@[ on database ~A~]: ~A / ~A~%  ~A"
+                    (sql-error-database c)
                     (sql-error-error-id c)
                     (sql-error-secondary-error-id c)
                     (sql-error-database-message c))))
@@ -58,9 +57,11 @@ set to :error to signal an error or :ignore/nil to silently ignore the warning."
                  :reader sql-error-connection-spec))
   (:report (lambda (c stream)
             (format stream "While trying to connect to database ~A~%  using database-type ~A:~%  Error ~D / ~A~%  has occurred."
-                    (database-name-from-spec
-                     (sql-error-connection-spec c)
-                     (sql-error-database-type c))
+                    (when (and (sql-error-connection-spec c)
+                               (sql-error-database-type c))
+                      (database-name-from-spec
+                       (sql-error-connection-spec c)
+                       (sql-error-database-type c)))
                     (sql-error-database-type c)
                     (sql-error-error-id c)
                     (sql-error-database-message c))))
@@ -111,6 +112,8 @@ connection is no longer usable."))
 (defun signal-closed-database-error (database)
   (error 'sql-fatal-error
         :database database
+        :connection-spec (when database (connection-spec database))
+        :database-type (when database (database-type database))
         :message "Database is closed."))
 
 (defun signal-no-database-error (database)
@@ -122,9 +125,9 @@ connection is no longer usable."))
 ;;; CLSQL Extensions
 
 (define-condition sql-warning (warning sql-condition)
-  ((message :initarg :message :reader sql-warning-message))
+  ((message :initarg :message :initform nil :reader sql-warning-message))
   (:report (lambda (c stream)
-            (format stream (sql-warning-message c)))))
+            (format stream "~A" (sql-warning-message c)))))
 
 (define-condition sql-database-warning (sql-warning)
   ((database :initarg :database :reader sql-warning-database))