Description:
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.00 sec)
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t1(s1 char(20) character set latin1);
Query OK, 0 rows affected (0.00 sec)
mysql> set LC_TIME_NAMES = 'fr_FR';
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values (monthname('2004-02-02'));
Query OK, 1 row affected (0.00 sec)
mysql> select hex(s1) from t1;
+------------------+
| hex(s1) |
+------------------+
| 66C3A97672696572 |
+------------------+
1 row in set (0.00 sec)
February in French is "février". The second letter is
"SMALL LETTER E WITH ACUTE ABOVE". It's latin1 code is 0xE9.
The result is wrong:
66 + C3A9 + 7672696572
The correct result should be:
66 + E9 + 7672696572
Conversion from utf8 to latin1 didn't happen.
The same problem happends with DAYNAME():
mysql> set lc_time_names=sv_SE;
Query OK, 0 rows affected (0.00 sec)
mysql> select dayname('2004-02-01');
+-----------------------+
| dayname('2004-02-01') |
+-----------------------+
| söndag |
+-----------------------+
1 row in set (0.00 sec)
mysql> insert into t1 values (dayname('2004-02-01'));
Query OK, 1 row affected (0.00 sec)
mysql> select hex(s1) from t1;
+----------------+
| hex(s1) |
+----------------+
| 73C3B66E646167 |
+----------------+
1 row in set (0.00 sec)
The above result is wrong again.
The correct result should be:
73 + F6 + 6E646167
where 0xF6 is latin1 code for "SMALL LETTER O WITH DIAERESIS".
How to repeat:
Run the above tests.
Suggested fix:
Monthname() and Dayname() must be converted to the target character set.
Description: mysql> drop table if exists t1; Query OK, 0 rows affected (0.00 sec) mysql> set names utf8; Query OK, 0 rows affected (0.00 sec) mysql> create table t1(s1 char(20) character set latin1); Query OK, 0 rows affected (0.00 sec) mysql> set LC_TIME_NAMES = 'fr_FR'; Query OK, 0 rows affected (0.00 sec) mysql> insert into t1 values (monthname('2004-02-02')); Query OK, 1 row affected (0.00 sec) mysql> select hex(s1) from t1; +------------------+ | hex(s1) | +------------------+ | 66C3A97672696572 | +------------------+ 1 row in set (0.00 sec) February in French is "février". The second letter is "SMALL LETTER E WITH ACUTE ABOVE". It's latin1 code is 0xE9. The result is wrong: 66 + C3A9 + 7672696572 The correct result should be: 66 + E9 + 7672696572 Conversion from utf8 to latin1 didn't happen. The same problem happends with DAYNAME(): mysql> set lc_time_names=sv_SE; Query OK, 0 rows affected (0.00 sec) mysql> select dayname('2004-02-01'); +-----------------------+ | dayname('2004-02-01') | +-----------------------+ | söndag | +-----------------------+ 1 row in set (0.00 sec) mysql> insert into t1 values (dayname('2004-02-01')); Query OK, 1 row affected (0.00 sec) mysql> select hex(s1) from t1; +----------------+ | hex(s1) | +----------------+ | 73C3B66E646167 | +----------------+ 1 row in set (0.00 sec) The above result is wrong again. The correct result should be: 73 + F6 + 6E646167 where 0xF6 is latin1 code for "SMALL LETTER O WITH DIAERESIS". How to repeat: Run the above tests. Suggested fix: Monthname() and Dayname() must be converted to the target character set.