Bug #28832 SET character_set_client = ucs2 is exected, but server doesn't parse UCS2

Submitted: 1 Jun 2007 11:13 Modified: 17 Oct 2007 9:29
Reporter: Jan Kneschke Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.17, 5.0, 4.1 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: bfsm_2007_10_18

[1 Jun 2007 11:13] Jan Kneschke
Description:
The SQL parser is not capable of parsing any UCS2 strings, but allows the client to request it with

> SET character_set_client = ucs2;

How to repeat:
In 5.0+ UCS2 as result is supported:

> SET character_set_results = ucs2;
> SELECT @@character_set_results;
|  u c s 2                    |

(\0u\0c\0s\0002)

> SET character_set_client = ucs2;
> \0S\0E\0L\0E\0C\0T\0 \0001

fails with:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\' at line 1

> SELECT 1

fails with:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'SELECT 1\' at line 1

... this is the wrong byte-stream for the charset, but it shows that somewhere internally something is expecting UCS2 now.

Test-Code:

#include <stdio.h>
#include <mysql.h>

#define C(x) x, sizeof(x) - 1

int exec_select(MYSQL *mysql, const char *q, size_t q_len) {
        MYSQL_RES *res;

        if (mysql_real_query(mysql, q, q_len)) {
               fprintf(stderr, "%s.%d: mysql_real_query(%s) failed: %s",
                                __FILE__, __LINE__,
                                "",
                                mysql_error(mysql));
               return 0;
        }

        if (NULL != (res = mysql_store_result(mysql))) {
                mysql_free_result(res);
        }

        return 0;
}

int main() {
        MYSQL *mysql;

        mysql = mysql_init(NULL);

        if (!mysql_real_connect(mysql, "127.0.0.1", "root", "", "", 3306, NULL, 0)) {
                fprintf(stderr, "%s.%d: mysql_real_connect() failed: %s", __FILE__, __LINE__, mysql_error(mysql));
                return -1;
        }

#if 0
        exec_select(mysql, C("SET character_set_results = ucs2"));
        exec_select(mysql, C("SELECT @@character_set_results"));
#else
        exec_select(mysql, C("SET character_set_client = ucs2"));
        exec_select(mysql, C("\0S" "\0E" "\0L" "\0E" "\0C" "\0T" "\0 " "\0""1"));
        exec_select(mysql, C("SELECT 1"));
#endif

        mysql_close(mysql);

        return 0;
}

Suggested fix:
return an error for:

SET character_set_client = ucs2;
[1 Jun 2007 12:55] Sveta Smirnova
Thank you for the report.

Verified as described.
[17 Oct 2007 9:29] Ramil Kalimullin
See bug #31615: crash after set names ucs2 collate xxx

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.