MySQL stored procedure - distinguish between note and error -


i have stored procedure executes stored sql.

however, error-handler kicks-in , exits if user attempts execute

drop temporary table if exists t_person; 

and 't_person' doesn't exist. i'm happy generate error when 'if exists' not given, how avoid error earlier case (the error-code unchanged)?

here's error handler:

declare exit handler sqlexception begin   set @sql = 'select \'invalid sql or bad parameter resulting in invalid sql\' `error`';   prepare stmt @sql;   execute stmt; end; 

you use continue handler rather an exit handler catches mysql error 1051 "unknown table"...

declare continue handler 1051 begin end; 

-or-

declare continue handler sqlstate '42s02' begin end; 

edit

to catch mysql error in exception handler, need specify mysql error number or corresponding sqlstate caught. (you specify named condition, named condition has resolve mysql error number or sqlstate).

a syntax error throw mysql error 1064.

if table foo exists, , issue

create temporary table if not exists `foo` (id int); 

that throw mysql error 1050.

to catch error, declare handler that. assuming want "swallow" exception , continue processing...

declare continue handler 1050 begin end; 

reference: https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html


like p_person in drop temporary table statement looks wrong me; @ least, i'm not familiar using like keyword in drop table statement.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -