Bug #5908 Triggers: crash caused by invalid value when sql_mode='traditional'
Submitted: 5 Oct 2004 19:20 Modified: 29 Jun 2005 17:38
Reporter: Trudy Pelzer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.2-alpha-debug OS:Linux (SuSE 9.1)
Assigned to: Dmitry Lenev CPU Architecture:Any

[5 Oct 2004 19:20] Trudy Pelzer
Description:
If a trigger's action will set a column to an invalid 
(out-of-range) value, and sql_mode='traditional', 
firing the trigger causes a crash. 
 
If sql_mode='', the crash does not happen, and 
the correct action is performed. 

How to repeat:
mysql> set sql_mode='traditional'; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> create table t1 (col1 tinyint, col2 int) engine=innodb; 
Query OK, 0 rows affected (0.01 sec) 
 
mysql> insert into t1 values(0,10); 
Query OK, 1 row affected (0.00 sec) 
 
mysql> select * from t1; 
+------+------+ 
| col1 | col2 | 
+------+------+ 
|    0 |   10 | 
+------+------+ 
1 row in set (0.00 sec) 
 
mysql> create trigger t1_trigger before update on t1 for each row set new.col1=1000; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> update t1 set col2=50; 
ERROR 2013 (HY000): Lost connection to MySQL server during query 
-- Note: The response should be SQLSTATE 22003 numeric value out of range
[6 Oct 2004 0:27] MySQL Verification Team
Verified against latest BK source tree.
[6 Oct 2004 0:59] MySQL Verification Team
Tested also on Windows, however the server doesn't crash like on Linux:

c:\mysql\bin>mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.2-alpha-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

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

mysql> create table t1 (col1 tinyint, col2 int) engine=innodb;
Query OK, 0 rows affected (0.19 sec)

mysql> insert into t1 values(0,10);
Query OK, 1 row affected (0.06 sec)

mysql> select * from t1;
+------+------+
| col1 | col2 |
+------+------+
|    0 |   10 |
+------+------+
1 row in set (0.02 sec)

mysql> create trigger t1_trigger before update on t1 for each row set
    -> new.col1=1000;
Query OK, 0 rows affected (0.04 sec)

mysql> update t1 set col2=50;
ERROR 1264 (22003): Out of range value adjusted for column 'col1' at row 1
mysql>
[29 Jun 2005 16:58] Matthias Leich
I checked this bug today under Linux and I get the correct response
   update t1 set col2=50;
   ERROR 22003: Out of range value adjusted for column 'col1' at row 1
without any crash.
My environment:
   - Intel PC with Linux(SuSE 9.3)
   - MySQL compiled from source
        Version 5.0 ChangeSet@1.1989.2.1, 2005-06-23
So I guess the reason for this bug was removed during other bug fixes.
Maybe a second check under Windows would make sense.
[29 Jun 2005 17:38] MySQL Verification Team
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

I tested on Linux and Windows and the crash not happens anymore
on both platforms.