简体   繁体   English

从存储过程处理程序中访问错误堆栈

[英]Access the error stack from within a stored procedure handler

I have stored procedure that calls another stored procedure. 我有存储过程调用另一个存储过程。 Let's call them OUTER and INNER. 我们称它们为OUTER和INNER。

The INNER procedure can detect errors in the input and if it does it will raise/signal it like this INNER过程可以检测输入中的错误,如果这样做,它将像这样引发/发出信号

signal sqlstate '45000' set message_text = 'some error';

In OUTER procedure I'm able to catch this with a normal handler like this 在OUTER程序中,我可以使用像这样的普通处理程序来捕获

declare exit handler for sqlstate '45000'
begin
  -- this is where I'd like to access the message_text from INNER
end    

but I fail to find a way of reading the internal parts of the signal. 但是我找不到找到读取信号内部部分的方法。

I've seen that it might be available in 5.6 but that isn't GA yet and will probably be shaky for a while after release. 我已经看到它可能在5.6中可用,但尚未发布,在发布后可能会不稳定。

Any takers on this.? 任何接受者。?

When a SQL condition (warning, error) is raised and then caught in an exception handler, the only way to know details about what happened is to use the GET DIAGNOSTICS statement. 当引发SQL条件(警告,错误),然后将其捕获到异常处理程序中时,了解发生的详细信息的唯一方法是使用GET DIAGNOSTICS语句。

See the doc: http://dev.mysql.com/doc/refman/5.6/en/get-diagnostics.html 参见文档: http : //dev.mysql.com/doc/refman/5.6/en/get-diagnostics.html

This statement is indeed only available starting with 5.6. 实际上,该语句仅从5.6开始可用。

For 5.5 and earlier, there is no way to get access -- that is, from code in an exception handler -- to the data you are looking for. 对于5.5及更早版本,无法访问(即从异常处理程序中的代码)访问所要查找的数据。

As this is not available until 5.6 I ended up creating a stored procedure that both sends the signal but also sets the error text in a session varible 因为直到5.6才可用,所以我最终创建了一个存储过程,该过程既发送信号,又在会话变量中设置错误文本

delimiter //

create procedure send_signal (error_text varchar(255))
begin
  set @session_error_text := error_text;
  signal sqlstate '45000' set message_text = error_text;
end//

delimiter ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM