diff --git a/mysql-test/main/type_varchar_mysql41.result b/mysql-test/main/type_varchar_mysql41.result index c908e94ed52..caf4ac84f02 100644 --- a/mysql-test/main/type_varchar_mysql41.result +++ b/mysql-test/main/type_varchar_mysql41.result @@ -240,7 +240,7 @@ ALTER IGNORE TABLE t1 MODIFY a VARBINARY(255) DEFAULT 'a11'; CALL show_table; Table Create Table t1 CREATE TABLE `t1` ( - `a` varbinary(255) DEFAULT 'a11', + `a` varbinary(255) DEFAULT x'613131', `b` varchar(255) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci VERSION @@ -251,7 +251,7 @@ ALTER IGNORE TABLE t1 MODIFY a VARBINARY(255) DEFAULT 'a12'; CALL show_table; Table Create Table t1 CREATE TABLE `t1` ( - `a` varbinary(255) DEFAULT 'a12', + `a` varbinary(255) DEFAULT x'613132', `b` varchar(255) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci VERSION diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index ecb8d8d999b..db0fdcceebb 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -316,3 +316,14 @@ f 1111 drop view v; drop table t; +# +# MDEV-35245 SHOW CREATE TABLE produces unusable statement for vector fields with constant default value +# +create table t1 (f vector(1) default 0x30313233, v vector(2) default x'4041424344454647'); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f` vector(1) DEFAULT x'30313233', + `v` vector(2) DEFAULT x'4041424344454647' +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +drop table t1; diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index a566c898bef..f1128635f6f 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -246,3 +246,10 @@ create algorithm=temptable view v as select * from t; select v1.f from v v1 natural join v v2; drop view v; drop table t; + +--echo # +--echo # MDEV-35245 SHOW CREATE TABLE produces unusable statement for vector fields with constant default value +--echo # +create table t1 (f vector(1) default 0x30313233, v vector(2) default x'4041424344454647'); +show create table t1; +drop table t1; diff --git a/mysql-test/suite/engines/funcs/r/tc_column_default_string.result b/mysql-test/suite/engines/funcs/r/tc_column_default_string.result index 62eda43ab36..433aa12288d 100644 --- a/mysql-test/suite/engines/funcs/r/tc_column_default_string.result +++ b/mysql-test/suite/engines/funcs/r/tc_column_default_string.result @@ -30,7 +30,7 @@ t14 SHOW CREATE TABLE t14; Table Create Table t14 CREATE TABLE `t14` ( - `c1` binary(10) DEFAULT 'x\0\0\0\0\0\0\0\0\0' + `c1` binary(10) DEFAULT x'78000000000000000000' ) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t14; SHOW TABLES; @@ -42,7 +42,7 @@ t14 SHOW CREATE TABLE t14; Table Create Table t14 CREATE TABLE `t14` ( - `c1` varbinary(10) DEFAULT 'x' + `c1` varbinary(10) DEFAULT x'78' ) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t14; SHOW TABLES; @@ -78,7 +78,7 @@ t14 SHOW CREATE TABLE t14; Table Create Table t14 CREATE TABLE `t14` ( - `c1` binary(10) NOT NULL DEFAULT 'x\0\0\0\0\0\0\0\0\0' + `c1` binary(10) NOT NULL DEFAULT x'78000000000000000000' ) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t14; SHOW TABLES; @@ -90,7 +90,7 @@ t14 SHOW CREATE TABLE t14; Table Create Table t14 CREATE TABLE `t14` ( - `c1` varbinary(10) NOT NULL DEFAULT 'x' + `c1` varbinary(10) NOT NULL DEFAULT x'78' ) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t14; SHOW TABLES; diff --git a/mysql-test/suite/funcs_1/r/is_columns_innodb.result b/mysql-test/suite/funcs_1/r/is_columns_innodb.result index 253d7993abe..2145322f16e 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_innodb.result +++ b/mysql-test/suite/funcs_1/r/is_columns_innodb.result @@ -534,7 +534,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob select,insert,update,references NEVER NULL NO NO def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob select,insert,update,references NEVER NULL NO NO def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob select,insert,update,references NEVER NULL NO NO -def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO +def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO diff --git a/mysql-test/suite/funcs_1/r/is_columns_memory.result b/mysql-test/suite/funcs_1/r/is_columns_memory.result index e84fffac4f3..f916b690b34 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_memory.result +++ b/mysql-test/suite/funcs_1/r/is_columns_memory.result @@ -529,7 +529,7 @@ def test tb3 f119 2 '' NO char 1 1 NULL NULL NULL latin1 latin1_bin char(1) s def test tb3 f120 3 '' NO char 1 1 NULL NULL NULL latin1 latin1_swedish_ci char(1) select,insert,update,references NEVER NULL NO NO def test tb3 f121 4 NULL YES char 50 50 NULL NULL NULL latin1 latin1_swedish_ci char(50) select,insert,update,references NEVER NULL NO NO def test tb3 f122 5 NULL YES char 50 50 NULL NULL NULL latin1 latin1_swedish_ci char(50) select,insert,update,references NEVER NULL NO NO -def test tb3 f129 6 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO +def test tb3 f129 6 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO def test tb3 f130 7 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO def test tb3 f131 8 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO def test tb3 f132 9 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO diff --git a/mysql-test/suite/funcs_1/r/is_columns_myisam.result b/mysql-test/suite/funcs_1/r/is_columns_myisam.result index 398a6ecb2c6..ba7bc43cb20 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_myisam.result +++ b/mysql-test/suite/funcs_1/r/is_columns_myisam.result @@ -591,7 +591,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob select,insert,update,references NEVER NULL NO NO def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob select,insert,update,references NEVER NULL NO NO def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob select,insert,update,references NEVER NULL NO NO -def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO +def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO diff --git a/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result index 04ada856c88..fc86b1b1ca4 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result @@ -591,7 +591,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob NEVER NULL NO NO def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob NEVER NULL NO NO def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob NEVER NULL NO NO -def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) NEVER NULL NO NO +def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) NEVER NULL NO NO def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) NEVER NULL NO NO def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned NEVER NULL NO NO def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill NEVER NULL NO NO diff --git a/sql/sql_show.cc b/sql/sql_show.cc index b7f2e80f3ef..e58acef386f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1863,28 +1863,38 @@ static bool get_field_default_value(THD *thd, Field *field, String *def_value, str.qs_append('\''); str.qs_append(field->val_int(), 2); str.qs_append('\''); - quoted= 0; + def_value->append(str); } else { field->val_str(&str); if (!field->str_needs_quotes()) quoted= 0; + if (str.length()) + { + if (str.charset() == &my_charset_bin) + { + def_value->append('x'); + def_value->append('\''); + def_value->append_hex(str.ptr(), str.length()); + def_value->append('\''); + } + else + { + StringBuffer def_val; + uint dummy_errors; + /* convert to system_charset_info == utf8 */ + def_val.copy(str.ptr(), str.length(), field->charset(), + system_charset_info, &dummy_errors); + if (quoted) + append_unescaped(def_value, def_val.ptr(), def_val.length()); + else + def_value->append(def_val); + } + } + else if (quoted) + def_value->set(STRING_WITH_LEN("''"), system_charset_info); } - if (str.length()) - { - StringBuffer def_val; - uint dummy_errors; - /* convert to system_charset_info == utf8 */ - def_val.copy(str.ptr(), str.length(), field->charset(), - system_charset_info, &dummy_errors); - if (quoted) - append_unescaped(def_value, def_val.ptr(), def_val.length()); - else - def_value->append(def_val); - } - else if (quoted) - def_value->set(STRING_WITH_LEN("''"), system_charset_info); } else if (field->maybe_null() && quoted) def_value->set(STRING_WITH_LEN("NULL"), system_charset_info); // Null as default diff --git a/storage/rocksdb/mysql-test/rocksdb/r/col_opt_not_null.result b/storage/rocksdb/mysql-test/rocksdb/r/col_opt_not_null.result index 2f948429e9e..ec7d5c5f2b4 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/col_opt_not_null.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/col_opt_not_null.result @@ -75,7 +75,7 @@ c BINARY NOT NULL DEFAULT 0 SHOW COLUMNS IN t1; Field Type Null Key Default Extra pk int(11) NO PRI NULL auto_increment -c binary(1) NO 0 +c binary(1) NO x'30' ALTER TABLE t1 ADD COLUMN err BINARY NOT NULL DEFAULT NULL; ERROR 42000: Invalid default value for 'err' INSERT INTO t1 (c) VALUES (NULL); @@ -209,7 +209,7 @@ c VARBINARY(64) NOT NULL DEFAULT 'test' SHOW COLUMNS IN t1; Field Type Null Key Default Extra pk int(11) NO PRI NULL auto_increment -c varbinary(64) NO test +c varbinary(64) NO x'74657374' ALTER TABLE t1 ADD COLUMN err VARBINARY(64) NOT NULL DEFAULT NULL; ERROR 42000: Invalid default value for 'err' INSERT INTO t1 (c) VALUES (NULL); diff --git a/storage/rocksdb/mysql-test/rocksdb/r/col_opt_null.result b/storage/rocksdb/mysql-test/rocksdb/r/col_opt_null.result index 37be694b8c0..95101490235 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/col_opt_null.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/col_opt_null.result @@ -60,7 +60,7 @@ SHOW COLUMNS IN t1; Field Type Null Key Default Extra c binary(1) YES NULL c1 binary(1) YES NULL -c2 binary(1) YES 0 +c2 binary(1) YES x'30' pk int(11) NO PRI NULL auto_increment INSERT INTO t1 (c,c1,c2) VALUES (NULL,NULL,NULL); INSERT INTO t1 (c,c1,c2) VALUES (0,0,0); @@ -183,7 +183,7 @@ SHOW COLUMNS IN t1; Field Type Null Key Default Extra c varbinary(64) YES NULL c1 varbinary(64) YES NULL -c2 varbinary(64) YES test +c2 varbinary(64) YES x'74657374' pk int(11) NO PRI NULL auto_increment INSERT INTO t1 (c,c1,c2) VALUES (NULL,NULL,NULL); INSERT INTO t1 (c,c1,c2) VALUES ('test','test','test');