will IF SIGNAL SQLSTATE in mariadb exit stored procedure? -
i don't quite understand how mariadb signals work.
i have stored procedure takes string input. testing string valid characters. if invalid characters found want send signal error invalid. stored procedure exit if signal sqlstate '......' set mesage_text='......'
raised? or complete procedure before issuing signal?
when using if...then
statements not seem work.
create procedure `testp`() begin if teststringsecurity('he;llo world') != 0 select 'invalid characters'; end if; select 'good go'; end;
always returns good go
. seems must wrap in if ... ... else
valid case. though setting signal different.
create procedure `testp`() begin if teststringsecurity('he;llo') != 0 select 'invalid characters'; else select 'good go'; end if; end
using signal
seem interrupt execution immediately.
create procedure `testp`() begin declare exit handler sqlexception begin diagnostics condition 1 @sqlstate = returned_sqlstate, @errno = mysql_errno, @text = message_text; set @full_error = concat("error ", @errno, " (", @sqlstate, "): ", @text); select @full_error; end; declare exit handler not found begin select concat('error: ',@str,' retruned not found exception.'); end; if teststringsecurity('he;llo') != 0 signal sqlstate '42000' set message_text = 'error: invalid string'; end if; select 'good go'; end
returns 'error 1644 (42000): error: invalid string'
Comments
Post a Comment