Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.7.2
-
None
-
LSB Version: n/a
Distributor ID: ManjaroLinux
Description: Manjaro Linux
Release: 25.0.0
Codename: Zetar
Description
when combining an error handler for 1048 and an insert...returning in a procedure, a strange behavior appears when the insert fails.
In the example below, the `credits` field of the `grafeia_fin_trans` table cannot be null.
So when total-factor is less than 0 the insert fails, as it is supposed to do.
Everything works well when the 'returning id, grafeio' is commented.
If it is uncommented then I get the screen I paste under the declaration of the procedure.
CREATE PROCEDURE test.add_grafeia_transaction(gr_id int, trans_type int) |
BEGIN
|
DECLARE insert_failed int default TRUE; |
DECLARE gr_total decimal; |
begin
|
DECLARE continue HANDLER FOR 1048 |
BEGIN |
set insert_failed = false; |
END; |
INSERT INTO `grafeia_fin_trans`(`grafeio`, `trans_type`, `credits`, `json_param`) |
select grafeio, id, res, null from |
(
|
select b.*, if(total-factor < 0, null, total-factor) res, total from (select sum(credits) total from grafeia_fin_trans where grafeio=gr_id) a, |
(select gr_id grafeio, id, factor, null from grafeia_fin_trans_types where id = trans_type) b) x |
returning id, grafeio
|
;
|
end; |
if FALSE = insert_failed then |
select 0 id; |
else
|
select 1 id; |
end if; |
END |