initial patch for symbol storage refactoring
[clsql.git] / sql / conditions.lisp
index 549f8f869f7a8e155b47d0739851bdf545364e81..6fc1af5aa4017a980f9b356ea11a7084265cbb5b 100644 (file)
@@ -5,9 +5,7 @@
 ;;;; Name:     conditions.lisp
 ;;;; Purpose:  Error conditions for CLSQL
 ;;;;
-;;;; $Id$
-;;;;
-;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
+;;;; This file, part of CLSQL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
 ;;;;
 ;;;; CLSQL users are granted the rights to distribute and use this software
 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
@@ -136,3 +134,36 @@ connection is no longer usable."))
                      "While accessing database ~A~%  Warning: ~A~%  has occurred."
                      (sql-warning-database c)
                      (sql-warning-message c)))))
+
+(define-condition database-too-strange (sql-user-error)
+  ()
+  (:documentation "Used to signal cases where CLSQL is going to fail at
+    mapping your database correctly"))
+
+(defun signal-database-too-strange (message)
+  (error 'database-too-strange :message message))
+
+
+(define-condition sql-value-conversion-error (error)
+  ((expected-type :accessor expected-type :initarg :expected-type :initform nil)
+   (value :accessor value :initarg :value :initform nil)
+   (database :accessor database :initarg :database :initform nil)))
+
+(defun error-converting-value (val type &optional (database *default-database*))
+  (restart-case 
+      (error 'sql-value-conversion-error
+             :expected-type type :value val :database database)
+    (use-value (new-val)
+      :report
+      (lambda (stream)
+        (write-sequence
+         "Use a different value instead of this failed conversion" stream))
+      (values new-val t)
+      )))
+
+(defun maybe-error-converting-value
+    (new val type &optional (database *default-database*))
+  (if (typep new type)
+      new
+      (error-converting-value
+       val type database)))