| |
| ||||||
Re-implementing udf_init_error in MySQL 5.5 and upThis is a discussion on Re-implementing udf_init_error in MySQL 5.5 and up within the DWH Tip Feeds forums, part of the Data Warehousing Tips and Techniques category; To whom it may concern - Today, I received an email from a user of the udf_init_error UDF (which resides in the lib_mysqludf_udf library). The purpose of this UDF is ... |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
| | #1 |
| News Bot Join Date: Nov 2007
Posts: 15,067
![]() | To whom it may concern - Today, I received an email from a user of the udf_init_error UDF (which resides in the lib_mysqludf_udf library). The purpose of this UDF is to generate an error condition, which can be used to abruptly terminate a trigger or stored procedure. As such it is a workaround for bug #11661. This is all described extensively in my now ancient article here. The user wrote me because of a problem experienced in MySQL 5.5: ...calling select udf_init_error('Transaction Cannot Be Done Because....'); will return user friendly error message: Transaction Cannot Be Done Because..... But in MySQL 5.5, it returns Can't initialize function 'udf_init_error; Transaction Cannot Be Done Because.... The Can't initialize function 'udf_init_error; bit is so annoying! How can I get rid of that?I explained that the UDF still works like it should; it's just that at some point during the 5.0 lifecycle, the format of the error message was changed. (I can't recall exactly which version that was, but I did file bug #38452 that describes this issue). Anyway, I suggested to move away from using the udf_init_error() UDF, and port all dependent code to use the SIGNAL syntax instead, which was introduced in MySQL 5.5. (For a friendly introduction to using the SIGNAL syntax, please check out one of my prior articles). Unfortunately, for this particular user this would not be an easy task: The use of SIGNAL did come to my mind, but the implementation is not easy. I have thousands of stored routines to modify. Besides, I'm already satisfied with what the UDF does.On the one hand, It makes me happy to hear the udf_init_error() UDF served him so well that he wrote so many routines that rely on it; on the other hand, I feel bad that this is holding him back from upgrading to MySQL 5.5. For everybody that is in this same position, I'd like to suggest the following solution: simply re-implement udf_init_error() as a stored SQL function that uses the SIGNAL functionality instead. The error message returned to the client will not be exactly the same as in the olden MySQL 5.0 days, but at least there will not be an annoying complaint about a UDF that cannot be initialized. Here's a very simple example that illustrates how to do it:CREATE FUNCTION udf_init_error( p_message VARCHAR(80) ) RETURNS INTEGER DETERMINISTIC NO SQL BEGIN DECLARE err CONDITION FOR SQLSTATE '45000'; SIGNAL err SET MESSAGE_TEXT = p_message; RETURN 1; END;I hope this helps. More from Roland Bouman's Blog ... |
| | |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 50 Best Practices For Implementing Mobile CRM | Latest News Headlines | Forrester | 0 | 24th August 2011 03:01 AM |
| In Implementing BI, Hospital Officials Face KM Challenges | Latest News Headlines | Other International Vendors | 0 | 3rd March 2011 04:33 AM |
| Implementing Unstructured Data Analytics | Latest News Headlines | Other International Vendors | 0 | 1st March 2011 04:01 AM |
| Implementing A Data Management Strategy | Latest News Headlines | Other International Vendors | 0 | 28th October 2010 05:03 AM |
| Implementing a prediction market within a company means changing the way information | admin | Prediction Markets News Feeds | 0 | 19th December 2009 08:43 AM |
| | |
| | |