1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: conditions.lisp
6 ;;;; Purpose: Error conditions for CLSQL
10 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
17 (in-package #:clsql-sys)
19 (defvar *backend-warning-behavior* :warn
20 "Action to perform on warning messages from backend. Default is to :warn. May also be
21 set to :error to signal an error or :ignore/nil to silently ignore the warning.")
23 ;;; CommonSQL-compatible conditions
25 (define-condition sql-condition ()
28 (define-condition sql-error (simple-error)
31 (define-condition sql-database-error (sql-error)
32 ((error-id :initarg :error-id
34 :reader sql-error-error-id)
35 (secondary-error-id :initarg :secondary-error-id
37 :reader sql-error-secondary-error-id)
38 (database-message :initarg :message
40 :reader sql-error-database-message)
41 (database :initarg :database
43 :reader sql-error-database))
44 (:report (lambda (c stream)
45 (format stream "A database error occurred~A: ~A / ~A~% ~A"
46 (if (sql-error-database c)
47 (format nil " on database ~A" (sql-error-database c))
49 (sql-error-error-id c)
50 (sql-error-secondary-error-id c)
51 (sql-error-database-message c)))))
53 (define-condition sql-connection-error (sql-database-error)
54 ((database-type :initarg :database-type :initform nil
55 :reader sql-error-database-type)
56 (connection-spec :initarg :connection-spec :initform nil
57 :reader sql-error-connection-spec))
58 (:report (lambda (c stream)
59 (format stream "While trying to connect to database ~A~% using database-type ~A:~% Error ~D / ~A~% has occurred."
60 (database-name-from-spec
61 (sql-error-connection-spec c)
62 (sql-error-database-type c))
63 (sql-error-database-type c)
64 (sql-error-error-id c)
65 (sql-error-database-message c)))))
67 (define-condition sql-database-data-error (sql-database-error)
68 ((expression :initarg :expression :initarg nil
69 :reader sql-error-expression))
70 (:report (lambda (c stream)
71 (format stream "While accessing database ~A~% with expression ~S:~% Error ~D / ~A~% has occurred."
72 (sql-error-database c)
73 (sql-error-expression c)
74 (sql-error-error-id c)
75 (sql-error-database-message c)))))
77 (define-condition sql-temporary-error (sql-database-error)
80 (define-condition sql-user-error (sql-error)
81 ((message :initarg :message
82 :initform "Unspecified error"
83 :reader sql-user-error-message))
84 (:report (lambda (c stream)
85 (format stream "A CLSQL lisp code error occurred: ~A "
86 (sql-user-error-message c)))))
91 (defun signal-closed-database-error (database)
92 (error 'sql-connection-error
94 :message "Database is closed."))
96 (defun signal-no-database-error (database)
97 (error 'sql-database-error
99 :message (format nil "~A is not a database." database)))
104 (define-condition sql-warning (warning sql-condition)
105 ((message :initarg :message :reader sql-warning-message))
106 (:report (lambda (c stream)
107 (format stream (sql-warning-message c)))))
109 (define-condition sql-database-warning (sql-warning)
110 ((database :initarg :database :reader sql-warning-database))
111 (:report (lambda (c stream)
113 "While accessing database ~A~% Warning: ~A~% has occurred."
114 (sql-warning-database c)
115 (sql-warning-message c)))))