X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fconditions.lisp;h=5e805e172e11cc3464eafe0e261e92094cafec86;hp=6270f915ac945340538198ee1fccc6068a8f7d76;hb=78489032c6f66ce666ffe5e2e726503b61b94616;hpb=8c6c643e3debe875bd14408cc3129d8148dfd125 diff --git a/sql/conditions.lisp b/sql/conditions.lisp index 6270f91..5e805e1 100644 --- a/sql/conditions.lisp +++ b/sql/conditions.lisp @@ -17,15 +17,19 @@ (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-database-error (simple-error sql-condition) +(define-condition sql-error (simple-error sql-condition) + ()) + +(define-condition sql-database-error (sql-error) ((error-id :initarg :error-id :initform nil :reader sql-error-error-id) @@ -39,13 +43,12 @@ 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" - (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))))) + (sql-error-database-message c)))) + (:documentation "Used to signal an error in a CLSQL database interface.")) (define-condition sql-connection-error (sql-database-error) ((database-type :initarg :database-type :initform nil @@ -54,12 +57,15 @@ 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))))) + (sql-error-database-message c)))) + (:documentation "Used to signal an error in connecting to a database.")) (define-condition sql-database-data-error (sql-database-error) ((expression :initarg :expression :initarg nil @@ -69,39 +75,59 @@ set to :error to signal an error or :ignore/nil to silently ignore the warning." (sql-error-database c) (sql-error-expression c) (sql-error-error-id c) - (sql-error-database-message c))))) + (sql-error-database-message c)))) + (:documentation "Used to signal an error with the SQL data + passed to a database.")) (define-condition sql-temporary-error (sql-database-error) - ()) - -(define-condition sql-user-error (simple-error sql-condition) + () + (:documentation "Used to signal an error when the database +cannot currently process a valid interaction because, for +example, it is still executing another command possibly issued by +another user.")) + +(define-condition sql-timeout-error (sql-connection-error) + () + (:documentation "Used to signal an error when the database +times out while processing some operation.")) + +(define-condition sql-fatal-error (sql-connection-error) + () + (:documentation "Used to signal an error when the database +connection is no longer usable.")) + +(define-condition sql-user-error (sql-error) ((message :initarg :message :initform "Unspecified error" :reader sql-user-error-message)) (:report (lambda (c stream) (format stream "A CLSQL lisp code error occurred: ~A " - (sql-user-error-message c))))) + (sql-user-error-message c)))) + (:documentation "Used to signal lisp errors inside CLSQL.")) + ;; Signal conditions (defun signal-closed-database-error (database) - (cerror 'sql-connection-error - :message - (format nil "Trying to perform operation on closed database ~A." - 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) - (error 'sql-database-error - :message "Not a database: ~A." database)) + (error 'sql-database-error + :database database + :message (format nil "~A is not a database." database))) ;;; 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))