Bug #68770 SIGNAL SQLSTATE '01...' in trigger vanishes with nary a trace

Submitted: 26 Mar 2013 0:38 Modified: 26 Mar 2013 16:16
Reporter: Programmer Old Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.5.8-log OS:Windows (Vista)
Assigned to: Jon Olav Hauglid CPU Architecture:Any

[26 Mar 2013 0:38] Programmer Old
Description:
In this trigger,

create trigger mme before insert on uue for each row if new.ll = 0 then
signal sqlstate '22003' set message_text = 'I hate 0';
elseif new.ll < 0 then
set @s = 'qfusq';
signal sqlstate '01508' set message_text = 'Negativs are bad';
end if

when new.ll < 0 there is no trace in the output that the signal was done:

mysql> create table uue (ll int);
Query OK, 0 rows affected (0.03 sec)

mysql> delimiter ?
mysql> create trigger mme before insert on uue for each row if new.ll = 0 then
    -> signal sqlstate '22003' set message_text = 'I hate 0';
    -> elseif new.ll < 0 then
    -> set @s = 'qfusq';
    -> signal sqlstate '01508' set message_text = 'Negativs are bad';
    -> end if ?
Query OK, 0 rows affected (0.08 sec)

mysql> delimiter ;
mysql> insert into uue value (0);
ERROR 1644 (22003): I hate 0
mysql> set @s = 'mlavh';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into uue value (-1);
Query OK, 1 row affected (0.03 sec)

mysql> show warnings;
Empty set (0.00 sec)

mysql> select @s;
+-------+
| @s    |
+-------+
| qfusq |
+-------+
1 row in set (0.02 sec)

mysql> set sql_mode='traditional';
Query OK, 0 rows affected (0.00 sec)

mysql> set @s = 'wweww';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into uue value (-1);
Query OK, 1 row affected (0.02 sec)

mysql> show warnings;
Empty set (0.00 sec)

mysql> select @s;
+-------+
| @s    |
+-------+
| qfusq |
+-------+
1 row in set (0.00 sec)

mysql> select * from uue;
+------+
| ll   |
+------+
|   -1 |
|   -1 |
+------+
2 rows in set (0.00 sec)

mysql> signal sqlstate '01508' set message_text = 'Negativs are bad';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+------------------+
| Level   | Code | Message          |
+---------+------+------------------+
| Warning | 1642 | Negativs are bad |
+---------+------+------------------+
1 row in set (0.00 sec)

mysql> signal sqlstate '22003' set message_text = 'I hate 0';
ERROR 1644 (22003): I hate 0
mysql> show warnings;
+-------+------+----------+
| Level | Code | Message  |
+-------+------+----------+
| Error | 1644 | I hate 0 |
+-------+------+----------+
1 row in set (0.00 sec)

How to repeat:
create table uue (ll int);
delimiter ?
create trigger mme before insert on uue for each row if new.ll = 0 then
signal sqlstate '22003' set message_text = 'I hate 0';
elseif new.ll < 0 then
set @s = 'qfusq';
signal sqlstate '01508' set message_text = 'Negativs are bad';
end if ?
delimiter ;
insert into uue value (0);
set @s = 'mlavh';
insert into uue value (-1);
show warnings;
select @s;
set sql_mode='traditional';
set @s = 'wweww';
insert into uue value (-1);
show warnings;
select @s;
select * from uue;
signal sqlstate '01508' set message_text = 'Negativs are bad';
show warnings;
signal sqlstate '22003' set message_text = 'I hate 0';
show warnings;

Suggested fix:
Let all signals from triggers be reported as if directly entered, although the running not be interrupted.
[26 Mar 2013 8:31] Jon Olav Hauglid
Hello!

This is not a bug. SQLSTATE '01xxx' indicates a warning and
warnings are not preserved at the end of trigger execution
according to the SQL standard.

See Bug#55850 for an explanation.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.