Thank you for your help! If the status of the bug report you submitted changes, you will be notified. You may return here and check on the status or update your report at any time. That URL for your bug report is: http://bugs.mysql.com/35588.
Bug #35588 Incorrect work with character sets in stored functions
Submitted: 27 Mar 2008 3:51 Modified: 2 May 2008 17:23
Reporter: Mikhail Serov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Charsets Severity:S2 (Serious)
Version:5.0.22-log OS:Linux
Assigned to: CPU Architecture:Any
Tags: character sets, stored routines

[27 Mar 2008 3:51] Mikhail Serov
Description:
Data from string columns with non-latin characters are treated incorrectly in stored functions.

Note: stored procedures seem to behave correctly.
Note 2: MySQL server on Windows looks like free from this bug

mysql> use test
Database changed

mysql> SET NAMES utf8;
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE tbl (utf8column VARCHAR(255) COLLATE utf8_general_ci);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO tbl VALUES ('latin characters русские буквы');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM tbl\G
*************************** 1. row ***************************
utf8column: latin characters русские буквы
1 row in set (0.00 sec)

mysql> CREATE FUNCTION utf8function () RETURNS VARCHAR(255) CHARACTER SET utf8 DETERMINISTIC
    -> RETURN (SELECT utf8column FROM tbl LIMIT 1);
Query OK, 0 rows affected (0.03 sec)

mysql> SELECT utf8function() /* Here questions marks appear */;
+--------------------------------+
| utf8function()                 |
+--------------------------------+
| latin characters ??????? ????? |
+--------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+---------+------+-----------------------------------------------------+
| Level   | Code | Message                                             |
+---------+------+-----------------------------------------------------+
| Warning | 1265 | Data truncated for column 'utf8function()' at row 1 |
+---------+------+-----------------------------------------------------+
1 row in set (0.00 sec)

How to repeat:
use test;
SET NAMES utf8;
CREATE TABLE tbl (utf8column VARCHAR(255) COLLATE utf8_general_ci);
INSERT INTO tbl VALUES ('latin characters русские буквы');
SELECT * FROM tbl\G
CREATE FUNCTION utf8function () RETURNS VARCHAR(255) CHARACTER SET utf8 DETERMINISTIC
RETURN (SELECT utf8column FROM tbl LIMIT 1);
SELECT utf8function() /* Here questions marks appear */;
SHOW WARNINGS;
[27 Mar 2008 6:53] Valeriy Kravchuk
Thank you for a problem report. Please, try to repeat with a newer version, 5.0.51a, and inform about the results.

In case of the same problem, please, send the results of:

show variables like 'char%'\G

and 

echo $LANG from shell.
[27 Apr 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[2 May 2008 8:26] Mikhail Serov
Yes, really on 5.0.51 it worked properly.
[2 May 2008 17:23] Valeriy Kravchuk
Bug is not repeatable with 5.0.51a.