Re: Capture error messages using DECLARE statements
Hi,
When you want to stick with pure SP's there's apparently is no other way than to write a specific handler for each and every SQLSTATE that you anticipate, at least for now.
Right now, MySQL does not seem to implement a @@ERROR (SQL Server T-SQL) global variable or a SQLCODE/SQLERRM (Oracle PL/SQL) pair of globals, which is what you need, right?
It does seem likely to me that this is bound to be corrected quite soon, especially because this kind of information (SQLSTATE) is available to external programs/libraries communicating with the server.
Mean while, would it be possible to write a UDF which returns the value of SQLSTATE?
Interestingly, ISO 9075:1999 does not address this issue either, at least not explicitly. It does specify a GET DIAGNOSTICS statement (iso 9075:1999 ch19: Diagnostics management) wich supplies a generic mechanism for obtaining all kinds of diagnostics (not just errors).