Bug #6317 string function CHAR, parameter is NULL, wrong result
Submitted: 29 Oct 2004 9:44 Modified: 23 Feb 2005 18:17
Reporter: Matthias Leich Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:
Assigned to: Sergei Glukhov CPU Architecture:Any

[29 Oct 2004 9:44] Matthias Leich
Description:
The MySQL manual states :
CHAR(N,...)
    CHAR() interprets the arguments as integers and returns a string consisting of the characters given by the code values of those integers. NULL values are skipped.

In my example the NULL values are not skipped and a '^@' is inserted.
# Example from the manual for comparison
SELECT CHAR(77,121,83,81,'76') as my_column;
my_column
MySQL
# now the NULL must be skipped and we must get 'ySQL'
SELECT CHAR(NULL,121,83,81,'76') as my_column;
my_column
^@ySQL
# skipping one character means we must get a length of 4
SELECT CHAR_LENGTH(CHAR(NULL,121,83,81,'76')) as my_column;
my_column
5

My environment:
   - Intel PC with Linux(SuSE 9.1)
   - MySQL 4.1 compiled from source
        last ChangeSet@1.2061, 2004-10-28

How to repeat:
Please execute the statements above
[29 Oct 2004 9:49] Matthias Leich
The position (first,middle,last) of the function parameter set to NULL does
not affect the bug.
[1 Nov 2004 9:28] Sergei Glukhov
ChangeSet
  1.2070 04/11/01
  Fix for bug #6317: string function CHAR, parameter is NULL, wrong result
[23 Feb 2005 15:33] Sergei Glukhov
Fixed in 4.1.11
[23 Feb 2005 18:17] Paul Dubois
Noted in 4.1.11, 5.0.3 changelogs.