mysql存储过程怎样抓取报错信息?
迷茫
迷茫 2017-04-17 16:21:45
0
2
544

执行mysql存储过程;
怎样像o/m数据库抓取出报错信息输出到log表呢?
mssql可以直接引用ERROR_MESSAGE()

查资料只能到查到有错误时赋值变量,应该至少可以抓到个error code啊

  DECLARE t_error INT DEFAULT 0;
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error = 1;

大家看看怎么实现

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
Peter_Zhu

declare exit handler for sqlexception

BEGIN
 rollback;#或者看自己需求
 GET DIAGNOSTICS CONDITION 1 # dev.mysql.com/doc/refman/5.7/en/get-diagnostics.html
        @p2 = MESSAGE_TEXT;
        
    insert into tbl_log_info (SINFO,STYPE,STEMP,srun_info) 
values('proc_','proc_','action',@p2);
  commit;

END;  

/Start transaction/
start transaction;

左手右手慢动作

I finally got it done after spending an afternoon;
I have to say that the process control of mysql is very poor!mysql的流程控制好差劲!
错误发生时经常抓取不到error,code直接赋值null,这样判断事物提交时被坑了一把;
文档里的抓取数据影响行数的功能没测通,输出结果始终是0,可能用法也不对吧,没找到正确姿势.

另外推荐个mysql存储过程调试工具 dbForge Studio for MySQL
使用时记得只在测试库上debugWhen errors occur, I often cannot capture error, code code> directly assigns the value null, so that it is judged that the thing is being tricked when submitting;

The function of grabbing data in the document to affect the number of rows has not been tested, and the output result is always 0 code>, maybe the usage is wrong, I couldn’t find the correct posture.🎜 🎜In addition, I recommend a mysql stored procedure debugging tool dbForge Studio for MySQL🎜When using it, remember to only debug on the test library, because it will debug the storage Add code to the process and create a new library to store debugging information in the database.🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!