Error while doing insert/update in MySql -
i want capture error occurring during inserting or updating data in mysql stored procedures.
when data updated in db, no of rows modified can checked know whether update or insert happened or not, if rows affected 0 (same data updated again), may not error condition.
i want capture insert/update failed. please share light on same
my sp below
delimiter $$ create procedure `sp_test`( in param1 varchar(50), in param2 varchar(50) ) begin if updatecount > 0 update tbname set val = param1 con = param2; else insert tbname set val = param1,con = param2; end if; end$$ delimiter ;
i want track whether statements has executed or not.
i have added exception block below,
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;
no getting errors. think fine scenario. if 1 find better answer please post here.