diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 33080d23ade..f2f425c8107 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -10459,5 +10459,81 @@ HEX(a) 613F DROP TABLE t1; # +# MDEV-10134 Add full support for DEFAULT +# +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) DEFAULT CONCAT('ß') +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a),a FROM t1; +HEX(a) a +C39F ß +SET NAMES latin1; +ALTER TABLE t1 ADD b VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SET NAMES utf8; +ALTER TABLE t1 ADD c VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) DEFAULT CONCAT('ß'), + `b` varchar(30) DEFAULT CONCAT('ß'), + `c` varchar(30) DEFAULT CONCAT('ß') +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SELECT * FROM t1; +a b c +ß ß ß +SET NAMES latin1; +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SET NAMES utf8; +SELECT * FROM t1; +a b c +ß ß ß +DROP TABLE t1; +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) CHARACTER SET utf8 DEFAULT CONCAT('ß') +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a), a FROM t1; +HEX(a) a +C383C5B8 ß +DROP TABLE t1; +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) DEFAULT CONCAT('ß') +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +HEX(a) +DF +DROP TABLE t1; +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) CHARACTER SET utf8 DEFAULT CONCAT('ß') +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +HEX(a) +C39F +DROP TABLE t1; +# # End of 10.2 tests # diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 61bc1c58ecb..1ad6f02f607 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1982,6 +1982,60 @@ LOAD XML INFILE '../../std_data/loaddata/mdev9874.xml' INTO TABLE t1 CHARACTER S SELECT HEX(a) FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +# This test uses some magic codes: +# _latin1 0xC39F is "A WITH TILDE + Y WITH DIAERESIS" +# _utf8 0xC39F is "SHARP S" + +# "A WITH TILDE + Y WITH DIAERESIS" in DEFAULT. +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a),a FROM t1; +SET NAMES latin1; +ALTER TABLE t1 ADD b VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SET NAMES utf8; +ALTER TABLE t1 ADD c VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SHOW CREATE TABLE t1; +# Testing that DEFAULT is independent on the current "SET NAMES". +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SELECT * FROM t1; +SET NAMES latin1; +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SET NAMES utf8; +SELECT * FROM t1; +DROP TABLE t1; + +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a), a FROM t1; +DROP TABLE t1; + +# "SHARP S" in DEFAULT +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + --echo # --echo # End of 10.2 tests --echo # diff --git a/sql/set_var.cc b/sql/set_var.cc index 5392a0065ac..b178681e952 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -966,10 +966,8 @@ int set_var_collation_client::check(THD *thd) int set_var_collation_client::update(THD *thd) { - thd->variables.character_set_client= character_set_client; - thd->variables.character_set_results= character_set_results; - thd->variables.collation_connection= collation_connection; - thd->update_charset(); + thd->update_charset(character_set_client, collation_connection, + character_set_results); thd->protocol_text.init(thd); thd->protocol_binary.init(thd); return 0; diff --git a/sql/slave.cc b/sql/slave.cc index f02ef5e036b..27825c431d3 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3024,13 +3024,10 @@ void set_slave_thread_default_charset(THD* thd, rpl_group_info *rgi) { DBUG_ENTER("set_slave_thread_default_charset"); - thd->variables.character_set_client= - global_system_variables.character_set_client; - thd->variables.collation_connection= - global_system_variables.collation_connection; thd->variables.collation_server= global_system_variables.collation_server; - thd->update_charset(); + thd->update_charset(global_system_variables.character_set_client, + global_system_variables.collation_connection); thd->system_thread_info.rpl_sql_info->cached_charset_invalidate(); DBUG_VOID_RETURN; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 91f337fa713..fde894c0cf6 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -11774,7 +11774,6 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) { if (thd_init_client_charset(thd, uint2korr(next_field))) DBUG_RETURN(1); - thd->update_charset(); next_field+= 2; } @@ -11940,7 +11939,6 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio, DBUG_PRINT("info", ("client_character_set: %d", (uint) net->read_pos[8])); if (thd_init_client_charset(thd, (uint) net->read_pos[8])) return packet_error; - thd->update_charset(); end= (char*) net->read_pos+32; } else diff --git a/sql/sql_class.h b/sql/sql_class.h index 1cd09bf44fb..20af4ea243a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3417,6 +3417,22 @@ public: inline CHARSET_INFO *charset() { return variables.character_set_client; } void update_charset(); + void update_charset(CHARSET_INFO *character_set_client, + CHARSET_INFO *collation_connection) + { + variables.character_set_client= character_set_client; + variables.collation_connection= collation_connection; + update_charset(); + } + void update_charset(CHARSET_INFO *character_set_client, + CHARSET_INFO *collation_connection, + CHARSET_INFO *character_set_results) + { + variables.character_set_client= character_set_client; + variables.collation_connection= collation_connection; + variables.character_set_results= character_set_results; + update_charset(); + } inline Query_arena *activate_stmt_arena_if_needed(Query_arena *backup) { diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 625f40a7ff8..7869f7f540c 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -799,12 +799,9 @@ bool thd_init_client_charset(THD *thd, uint cs_number) if (!opt_character_set_client_handshake || !(cs= get_charset(cs_number, MYF(0)))) { - thd->variables.character_set_client= - global_system_variables.character_set_client; - thd->variables.collation_connection= - global_system_variables.collation_connection; - thd->variables.character_set_results= - global_system_variables.character_set_results; + thd->update_charset(global_system_variables.character_set_client, + global_system_variables.collation_connection, + global_system_variables.character_set_results); } else { @@ -814,10 +811,8 @@ bool thd_init_client_charset(THD *thd, uint cs_number) my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client", cs->csname); return true; - } - thd->variables.character_set_results= - thd->variables.collation_connection= - thd->variables.character_set_client= cs; + } + thd->update_charset(cs,cs,cs); } return false; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 8b3d50e40e4..63b44c53f94 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1710,10 +1710,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, decrease_user_connections(thd->user_connect); thd->user_connect= save_user_connect; thd->reset_db(save_db, save_db_length); - thd->variables.character_set_client= save_character_set_client; - thd->variables.collation_connection= save_collation_connection; - thd->variables.character_set_results= save_character_set_results; - thd->update_charset(); + thd->update_charset(save_character_set_client, save_collation_connection, + save_character_set_results); thd->failed_com_change_user++; my_sleep(1000000); } diff --git a/sql/table.cc b/sql/table.cc index 30e4d3c2517..ef30e2bf529 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -126,10 +126,7 @@ Default_object_creation_ctx::create_backup_ctx(THD *thd) const void Default_object_creation_ctx::change_env(THD *thd) const { - thd->variables.character_set_client= m_client_cs; - thd->variables.collation_connection= m_connection_cl; - - thd->update_charset(); + thd->update_charset(m_client_cs, m_connection_cl); } /**************************************************************************