Raise exception?

45 views
Skip to first unread message

Bèrto ëd Sèra

unread,
Jul 7, 2008, 4:39:05 AM7/7/08
to The UDF Repository for MySQL
Hello list.

Has anyone ever thought of making a UDF that would emulate an Oracle-style RAISE EXCEPTION command? MySQL is getting very nice with stored procedures and triggers, but on implementing business rules with such toills you are always confronted with the need of passing meaningful error messager to people who interface to the DB. So there is a real need for user-defined exceptions.

Any hint will be greatly appreciated.
Bèrto

Roland Bouman

unread,
Jul 7, 2008, 5:47:22 AM7/7/08
to The UDF Repository for MySQL
Hi!

> Has anyone ever thought of making a UDF that would emulate an Oracle-style
> RAISE EXCEPTION command? MySQL is getting very nice with stored procedures

yes, see:

http://rpbouman.blogspot.com/2005/11/using-udf-to-raise-errors-from-inside.html

You can find a UDF that raises an exception in lib_mysqludf_udf, see:

http://www.mysqludf.org/lib_mysqludf_udf/index.php#udf_init_error

(this uses a combination of a UDF and a stored procedure to set
@SQLERRM and @SQLCODE)

> and triggers, but on implementing business rules with such toills you are
> always confronted with the need of passing meaningful error messager to
> people who interface to the DB. So there is a real need for user-defined
> exceptions.

The real problem is though that you cannot distinguish between 'the
UDF crapped out on us' vs 'An exception was raised'
In the application code you can kind of work around that by looking
for the name of the particular udf though.

I hope this helps.

kind regards

Roland Bouman
Reply all
Reply to author
Forward
0 new messages