diff options
author | unknown <anozdrin/alik@station.> | 2007-09-28 23:30:54 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@station.> | 2007-09-28 23:30:54 +0400 |
commit | 20b08f4705a1f526b0e746ec5dcd065364971c03 (patch) | |
tree | 605786f152b4a3a692332f47c2dc95125435e7d5 /libmysql | |
parent | fa48986a0d1b8214a118b29b95a3e8fdb0fd9eb4 (diff) | |
download | mariadb-git-20b08f4705a1f526b0e746ec5dcd065364971c03.tar.gz |
Patch for BUG#30472: libmysql doesn't reset charset,
insert_id after succ. mysql_change_user() call.
See also WL 4066.
This bug reveals two problems:
- the problem on the client side which was described originally;
- the problem in protocol / the server side: connection context
on client and server should be like after mysql_real_connect()
and be consistent. The server however just resets character
set variables to the global defaults.
The fix seems to be as follows:
- extend the protocol so that the client be able to send
character set information in COM_CHANGE_USER command;
- change the server so that it understands client character set
in the command;
- change the client:
- reset character set to the default value (which has been
read from the configuration);
- send character set in COM_CHANGE_USER command.
client/client_priv.h:
Declare a function, used in libmysql.c and client.c.
libmysql/libmysql.c:
1. Reset character set on the client in mysql_change_user().
2. Send character set to the server in COM_CHANGE_USER command.
mysql-test/t/mysql_client_test.test:
mysql_client_test.log is used by the test suite.
Use mysql_client_test.out.log to collect mysql_client_test
real output.
sql/sql_parse.cc:
Switch character set in COM_CHANGE_USER.
tests/mysql_client_test.c:
Test case for BUG#30472.
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/libmysql.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index c8e2d48873f..e2e481fdd21 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -685,14 +685,25 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd) return 0; } - my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db) { char buff[512],*end=buff; int rc; + CHARSET_INFO *saved_cs= mysql->charset; + DBUG_ENTER("mysql_change_user"); + /* Get the connection-default character set. */ + + if (mysql_init_character_set(mysql)) + { + mysql->charset= saved_cs; + DBUG_RETURN(TRUE); + } + + /* Use an empty string instead of NULL. */ + if (!user) user=""; if (!passwd) @@ -721,6 +732,14 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, /* Add database if needed */ end= strmov(end, db ? db : "") + 1; + /* Add character set number. */ + + if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) + { + *end= (uchar) mysql->charset->number; + ++end; + } + /* Write authentication package */ simple_command(mysql,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1); @@ -743,6 +762,11 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, mysql->passwd=my_strdup(passwd,MYF(MY_WME)); mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; } + else + { + mysql->charset= saved_cs; + } + DBUG_RETURN(rc); } |