X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fconditions.lisp;h=e19805248bd5e6f9601a98db29a3e76157741238;hp=3ef94122cd93c884652c1d994490bea07eba3421;hb=HEAD;hpb=f1d668746523a72a6893a46380468a9e033545e4 diff --git a/sql/conditions.lisp b/sql/conditions.lisp index 3ef9412..e198052 100644 --- a/sql/conditions.lisp +++ b/sql/conditions.lisp @@ -142,3 +142,29 @@ connection is no longer usable.")) (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 (make-condition + '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)))