X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fconditions.lisp;h=1969b962ae28728e565ea2d6a11fd03f04c49acc;hp=51c06add66e442afd84b62920eee992b3368f8f5;hb=c1d990950afa607b9d7e428da384b057fd5c74f3;hpb=d2d49ab13c98bc7a1819a0fd3968268a5567bdc3 diff --git a/sql/conditions.lisp b/sql/conditions.lisp index 51c06ad..1969b96 100644 --- a/sql/conditions.lisp +++ b/sql/conditions.lisp @@ -134,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) + (continue () + :report "Continue using the unconverted value" + (values val t)) + (use-value (new-val) + :report "Use a different value instead of this failed conversion" + (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)))