diff options
-rw-r--r-- | client/mysqltest.cc | 9 | ||||
-rw-r--r-- | mysql-test/r/reset_connection.result | 20 | ||||
-rw-r--r-- | mysql-test/t/reset_connection.test | 15 | ||||
-rw-r--r-- | sql/sql_class.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.h | 3 | ||||
-rw-r--r-- | sql/sql_connect.cc | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 3 |
7 files changed, 51 insertions, 1 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 227c40f8d01..0d7b54acf8e 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5938,6 +5938,7 @@ void do_connect(struct st_command *command) int read_timeout= 0; int write_timeout= 0; int connect_timeout= 0; + char *csname=0; struct st_connection* con_slot; static DYNAMIC_STRING ds_connection_name; @@ -6049,6 +6050,11 @@ void do_connect(struct st_command *command) { connect_timeout= atoi(con_options + sizeof("connect_timeout=")-1); } + else if (strncasecmp(con_options, "CHARSET=", + sizeof("CHARSET=") - 1) == 0) + { + csname= strdup(con_options + sizeof("CHARSET=") - 1); + } else die("Illegal option to connect: %.*s", (int) (end - con_options), con_options); @@ -6086,7 +6092,7 @@ void do_connect(struct st_command *command) mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS); mysql_options(con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0); mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_NAME, - charset_info->csname); + csname?csname: charset_info->csname); if (opt_charsets_dir) mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_DIR, opt_charsets_dir); @@ -6197,6 +6203,7 @@ void do_connect(struct st_command *command) #ifdef HAVE_SMEM dynstr_free(&ds_shm); #endif + free(csname); DBUG_VOID_RETURN; } diff --git a/mysql-test/r/reset_connection.result b/mysql-test/r/reset_connection.result index 925195f704e..54f6ffdbd25 100644 --- a/mysql-test/r/reset_connection.result +++ b/mysql-test/r/reset_connection.result @@ -5,3 +5,23 @@ Com_select 10 SHOW local STATUS LIKE 'com_select'; Variable_name Value Com_select 0 +# Test if charset changes after reset (utf8) +connect utf8_conn,localhost,root,,,,,CHARSET=utf8; +connection utf8_conn; +SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT; +RESULT +OK +SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT; +RESULT +OK +disconnect utf8_conn; +# Test if charset changes after reset (latin1) +connect latin1_conn,localhost,root,,,,,CHARSET=latin1; +connection latin1_conn; +SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT; +RESULT +OK +SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT; +RESULT +OK +disconnect latin1_conn; diff --git a/mysql-test/t/reset_connection.test b/mysql-test/t/reset_connection.test index 49f41c32fc3..73c8280703c 100644 --- a/mysql-test/t/reset_connection.test +++ b/mysql-test/t/reset_connection.test @@ -23,3 +23,18 @@ SHOW local STATUS LIKE 'com_select'; SHOW local STATUS LIKE 'com_select'; +--echo # Test if charset changes after reset (utf8) +connect(utf8_conn,localhost,root,,,,,CHARSET=utf8); +connection utf8_conn; +SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT; +--reset_connection +SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT; +disconnect utf8_conn; + +--echo # Test if charset changes after reset (latin1) +connect(latin1_conn,localhost,root,,,,,CHARSET=latin1); +connection latin1_conn; +SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT; +--reset_connection +SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT; +disconnect latin1_conn;
\ No newline at end of file diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1146359f451..6592dcd8f6f 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -840,6 +840,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) prepare_derived_at_open= FALSE; create_tmp_table_for_derived= FALSE; save_prep_leaf_list= FALSE; + org_charset= 0; /* Restore THR_THD */ set_current_thd(old_THR_THD); inc_thread_count(); diff --git a/sql/sql_class.h b/sql/sql_class.h index 1d8730ae008..d678a20078a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2312,6 +2312,9 @@ public: uint dbug_sentry; // watch out for memory corruption #endif struct st_my_thread_var *mysys_var; + + /* Original charset number from the first client packet, or COM_CHANGE_USER*/ + CHARSET_INFO *org_charset; private: /* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 99fc1e8c1aa..278677b8b2d 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -793,6 +793,7 @@ bool thd_init_client_charset(THD *thd, uint cs_number) cs->csname); return true; } + thd->org_charset= cs; thd->update_charset(cs,cs,cs); } return false; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 244719f39a3..ef5d1afcab2 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1689,6 +1689,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->status_var.com_other++; thd->change_user(); thd->clear_error(); // if errors from rollback + /* Restore original charset from client authentication packet.*/ + if(thd->org_charset) + thd->update_charset(thd->org_charset,thd->org_charset,thd->org_charset); my_ok(thd, 0, 0, 0); break; } |