From 8f44d902bd96592891a61e5822a6fbe5446d11d1 Mon Sep 17 00:00:00 2001 From: "gluh@mysql.com/gluh.(none)" <> Date: Mon, 11 Sep 2006 14:50:46 +0500 Subject: [PATCH] Bug#20922 mysql removes a name of first column in a table 0xFF is internal separator for SET|ENUM names. If this symbol is present in SET|ENUM names then we replace it with ','(deprecated symbol for SET|ENUM names) during frm creation and restore to 0xFF during frm opening --- mysql-test/r/type_enum.result | 9 +++++++++ mysql-test/t/type_enum.test | 9 +++++++++ sql/table.cc | 16 +++++++++++++++- sql/unireg.cc | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result index ab3c441a7e2..0fe3f674fba 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1745,3 +1745,12 @@ create table t1 (a set('x','y') default 'x'); alter table t1 alter a set default 'z'; ERROR 42000: Invalid default value for 'a' drop table t1; +create table t1 (f1 int); +alter table t1 add f2 enum(0xFFFF); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` int(11) default NULL, + `f2` enum('ÿÿ') default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test index 0d479f312cd..68f5664c36d 100644 --- a/mysql-test/t/type_enum.test +++ b/mysql-test/t/type_enum.test @@ -127,4 +127,13 @@ create table t1 (a set('x','y') default 'x'); alter table t1 alter a set default 'z'; drop table t1; + +# +# Bug#20922 mysql removes a name of first column in a table +# +create table t1 (f1 int); +alter table t1 add f2 enum(0xFFFF); +show create table t1; +drop table t1; + # End of 4.1 tests diff --git a/sql/table.cc b/sql/table.cc index 7587531b2f9..f22caf36679 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -387,7 +387,21 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, count))) goto err_not_open; for (count= 0; count < interval->count; count++) - interval->type_lengths[count]= strlen(interval->type_names[count]); + { + char *val= (char*) interval->type_names[count]; + interval->type_lengths[count]= strlen(val); + /* + Replace all ',' symbols with NAMES_SEP_CHAR. + See the comment in unireg.cc, pack_fields() function + for details. + */ + for (uint cnt= 0 ; cnt < interval->type_lengths[count] ; cnt++) + { + char c= val[cnt]; + if (c == ',') + val[cnt]= NAMES_SEP_CHAR; + } + } interval->type_lengths[count]= 0; } } diff --git a/sql/unireg.cc b/sql/unireg.cc index e3bf763f700..16a0a66c3dd 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -637,6 +637,21 @@ static bool pack_fields(File file, List &create_fields, tmp.append(NAMES_SEP_CHAR); for (const char **pos=field->interval->type_names ; *pos ; pos++) { + char *val= (char*) *pos; + uint str_len= strlen(val); + /* + Note, hack: in old frm NAMES_SEP_CHAR is used to separate + names in the interval (ENUM/SET). To allow names to contain + NAMES_SEP_CHAR, we replace it with a comma before writing frm. + Backward conversion is done during frm file opening, + See table.cc, openfrm() function + */ + for (uint cnt= 0 ; cnt < str_len ; cnt++) + { + char c= val[cnt]; + if (c == NAMES_SEP_CHAR) + val[cnt]= ','; + } tmp.append(*pos); tmp.append(NAMES_SEP_CHAR); }