Bug #10797 Allow error code to be picked up in a stored procedure
Submitted: 23 May 2005 9:03 Modified: 14 Sep 2006 11:05
Reporter: Anders Karlsson Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:5.0 OS:
Assigned to: CPU Architecture:Any

[23 May 2005 9:03] Anders Karlsson
Description:
Allow a variable or a function that can pick up the latest error-code in a stored procedure. This is more or less a necessity when using one of the generic HANDLERs, i.e. SQLEXCEPTION. If an error occurs that is picked up by a SQLEXCEPTION handler is to do something useful, like logging the specific error or take some specific action based opn the errorcode itself.
Another useful effect of this is to allow for generic error handlers, that are CALLed by the SQLEXCEPTION handler, possibly passing the error as an argument or having this being globally accessible from the called procedure.

How to repeat:
This is a simple example of how this could look:
CREATE PROCEDURE foo()
   BEGIN
   DECLARE EXIT HANDLER FOR SQLEXCEPTION
     INSERT INTO errortable VALUES(recent_error());
   ... Some code ...
   END;
//
Where recent_error() is the name of the requested function that would return the most recent error.
[28 Sep 2005 11:05] Roland Bouman
I think this is a duplicate for: http://bugs.mysql.com/bug.php?id=11660
[14 Sep 2006 11:05] Valeriy Kravchuk
Duplicate of bug #11660.