MDEV-18281 COM_RESET_CONNECTION changes the connection encoding
Store original charset during client authentication, and restore it for COM_RESET_CONNECTION
This commit is contained in:
parent
14a58cea59
commit
e214aa1cd3
@ -5966,6 +5966,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;
|
||||
@ -6077,6 +6078,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);
|
||||
@ -6114,7 +6120,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);
|
||||
@ -6225,6 +6231,7 @@ void do_connect(struct st_command *command)
|
||||
#ifdef HAVE_SMEM
|
||||
dynstr_free(&ds_shm);
|
||||
#endif
|
||||
free(csname);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
@ -847,6 +847,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
|
||||
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();
|
||||
|
@ -2365,6 +2365,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
|
||||
|
@ -796,6 +796,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;
|
||||
|
@ -1715,6 +1715,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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user