Bug #11927 Warnings shown for CAST( chr as signed) but not (chr + 0)
Submitted: 13 Jul 2005 23:23 Modified: 13 Dec 2006 20:08
Reporter: Mark Leith Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:Current OS:Any (Any)
Assigned to: Georgi Kodinov CPU Architecture:Any

[13 Jul 2005 23:23] Mark Leith
Description:
Warnings are shown when using CAST() to cast a char to an integer, but when performing simple arithmetic to perform the same function, no warnings are given .

How to repeat:
create table t1 (x char(1));

insert into t1 values (1), (5), (3), ('a'), (6), ('t');

select * from t1 order by (x + 0);

select * from t1 order by cast( x as signed );

Suggested fix:
Show warnings for arithmetic against string types as done with CAST().
[16 Nov 2006 13:15] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/15418

ChangeSet@1.2305, 2006-11-16 15:14:37+02:00, gkodinov@macbook.gmz +13 -0
  BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
   When implicitly converting string fields to numbers the 
   string-to-number conversion error was not sent to the client.
   Added code to send the conversion error as warning.
   
   We also need to prevent generation of warnings from the places
   where val_xxx() methods are called for the sole purpose of updating
   the Item::null_value flag.
   To achieve that a special function is added (and called) : 
   update_null_value(). This function will set the no_errors flag and
   will call val_xxx(). The warning generation in Field_string::val_xxx()
   will use the flag when generating the conversion warnings.
[28 Nov 2006 13:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/15953

ChangeSet@1.2305, 2006-11-28 15:44:11+02:00, gkodinov@macbook.gmz +13 -0
  BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
   When implicitly converting string fields to numbers the 
   string-to-number conversion error was not sent to the client.
   Added code to send the conversion error as warning.
   
   We also need to prevent generation of warnings from the places
   where val_xxx() methods are called for the sole purpose of updating
   the Item::null_value flag.
   To achieve that a special function is added (and called) : 
   update_null_value(). This function will set the no_errors flag and
   will call val_xxx(). The warning generation in Field_string::val_xxx()
   will use the flag when generating the conversion warnings.
[1 Dec 2006 9:34] Georgi Kodinov
Pushed in 5.0.32/5.1.14-beta
[13 Dec 2006 20:08] Paul Dubois
Noted in 5.0.32, 5.1.14 changelogs.

Warnings were generated when explicitly casting a character to a
number (for example, CAST('x' AS SIGNED)), but not for implicit
conversions in simple arithmetic operations (such as 'x' + 0). Now
warnings are generated in all cases.