Bug #42910 | Triggers override strict sql_mode | ||
---|---|---|---|
Submitted: | 17 Feb 2009 6:31 | Modified: | 25 Sep 2014 15:33 |
Reporter: | Shlomi Noach (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.0.67 & 5.1.30, 5.0, 5.1, 6.0 bzr | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | SQL_MODE, trigger |
[17 Feb 2009 6:31]
Shlomi Noach
[17 Feb 2009 6:53]
Sveta Smirnova
Thank you for the report. Verified as described.
[18 Feb 2009 2:59]
Davi Arnaut
Triggers (or any stored program for this matter) are dependent on the SQL mode that was in effect at the time when the trigger was created, which remains in effect for this trigger whenever it is invoked, regardless of the current server SQL mode.
[18 Feb 2009 3:22]
Davi Arnaut
Futhermore, traditional mode only applies to INSERT and UPDATE statements but the bug here is probably that the warning is not being elevated to a error once its propagated back to the diagnostics area of the calling statement. This seems like a duplicate of Bug#23001
[18 Feb 2009 3:56]
Shlomi Noach
Davi, please notice that I have shown sql_mode to be TRADITIONAL *before* creating the trigger.
[18 Feb 2009 3:57]
Shlomi Noach
Davi, "...the warning is not propagated to an error..." I wouldn't mind that so much, if that were the case, but the case is an invalid value is inserted to the table. So I'm afraid your diagnostic is incorrect. Regards
[18 Feb 2009 7:15]
Sveta Smirnova
SQL_MODE was set before creating trigger in my case too: set sql_mode='STRICT_ALL_TABLES'; DROP TABLE IF EXISTS a; CREATE TABLE a ( id TINYINT UNSIGNED NOT NULL DEFAULT 0 ) ENGINE=MyISAM; --error 1264 INSERT INTO a VALUES (-1); DROP TRIGGER IF EXISTS a_BI; CREATE TRIGGER a_BI BEFORE INSERT ON a FOR EACH ROW SET NEW.id := -1; INSERT INTO a VALUES (18); SELECT * FROM a;
[18 Feb 2009 8:08]
Shlomi Noach
Hi, To clarify, I further set the sql_mode in my.cnf, and have restarted the server prior to the above test, so the server has started with TRADITIONAL.
[18 Feb 2009 10:49]
Davi Arnaut
I'm aware of the context here, I was just stating some facts about what happens internally and which will help whoever take this bug. The root issue here is that the server currently only aborts for INSERT and UPDATE statements, so if you do something like SET .. = 1/0 it won't abort either.. and this needs to be revisited. From a user perspective the problem may seem that invalidate data ends up in the table but internally the means to avoid this are a bit different as is implemented by a checks performed during INSERT and UPDATE statements that are responsible for propagating (or elevating) any warnings to errors.. and this check is not performed for a SET.
[18 Feb 2009 10:59]
Shlomi Noach
I see. Thanks for explaining! Cheers
[25 Sep 2014 15:33]
Paul DuBois
Noted in 5.7.5 changelog. In strict SQL mode, triggers could permit operations not permitted in strict mode.