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-database-error (simple-error sql-condition)
29 ((error-id :initarg :error-id
31 :reader sql-error-error-id)
32 (secondary-error-id :initarg :secondary-error-id
34 :reader sql-error-secondary-error-id)
35 (database-message :initarg :message
37 :reader sql-error-database-message)
38 (database :initarg :database
40 :reader sql-error-database))
41 (:report (lambda (c stream)
42 (format stream "A database error occurred: ~A / ~A~% ~A"
43 (if (sql-error-database c)
44 (format nil " on database ~A" (sql-error-database c))
46 (sql-error-error-id c)
47 (sql-error-secondary-error-id c)
48 (sql-error-database-message c)))))
50 (define-condition sql-connection-error (sql-database-error)
51 ((database-type :initarg :database-type :initform nil
52 :reader sql-error-database-type)
53 (connection-spec :initarg :connection-spec :initform nil
54 :reader sql-error-connection-spec))
55 (:report (lambda (c stream)
56 (format stream "While trying to connect to database ~A~% using database-type ~A:~% Error ~D / ~A~% has occurred."
57 (database-name-from-spec
58 (sql-error-connection-spec c)
59 (sql-error-database-type c))
60 (sql-error-database-type c)
61 (sql-error-error-id c)
62 (sql-error-database-message c)))))
64 (define-condition sql-database-data-error (sql-database-error)
65 ((expression :initarg :expression :initarg nil
66 :reader sql-error-expression))
67 (:report (lambda (c stream)
68 (format stream "While accessing database ~A~% with expression ~S:~% Error ~D / ~A~% has occurred."
69 (sql-error-database c)
70 (sql-error-expression c)
71 (sql-error-error-id c)
72 (sql-error-database-message c)))))
74 (define-condition sql-temporary-error (sql-database-error)
77 (define-condition sql-user-error (simple-error sql-condition)
78 ((message :initarg :message
79 :initform "Unspecified error"
80 :reader sql-user-error-message))
81 (:report (lambda (c stream)
82 (format stream "A CLSQL lisp code error occurred: ~A "
83 (sql-user-error-message c)))))
88 (defun signal-closed-database-error (database)
89 (cerror 'sql-connection-error
91 (format nil "Trying to perform operation on closed database ~A."
94 (defun signal-no-database-error (database)
95 (error 'sql-database-error
96 :message "Not a database: ~A." database))
101 (define-condition sql-warning (warning sql-condition)
102 ((message :initarg :message :reader sql-warning-message))
103 (:report (lambda (c stream)
104 (format stream (sql-warning-message c)))))
106 (define-condition sql-database-warning (sql-warning)
107 ((database :initarg :database :reader sql-warning-database))
108 (:report (lambda (c stream)
110 "While accessing database ~A~% Warning: ~A~% has occurred."
111 (sql-warning-database c)
112 (sql-warning-message c)))))