From 440db4c1dc5573f298c5be2c4d3937fe79921da8 Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Fri, 25 Oct 2002 15:08:47 +0500 Subject: [PATCH] ENUM/SET fields now have charset too --- mysql-test/r/show_check.result | 4 ++-- mysql-test/r/type_enum.result | 4 ++-- mysql-test/r/type_ranges.result | 12 ++++++------ mysql-test/r/type_set.result | 4 ++-- sql/field.cc | 26 ++++++++++++++++++++++---- sql/field.h | 10 +++++----- sql/sql_table.cc | 4 ++++ sql/sql_yacc.yy | 4 ++-- 8 files changed, 45 insertions(+), 23 deletions(-) diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 462abb29979..2e8d7d19465 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -93,13 +93,13 @@ c int not null comment 'int column' show create table t1 ; Table Create Table t1 CREATE TABLE `t1` ( - `test_set` set('val1','val2','val3') NOT NULL default '', + `test_set` set('val1','val2','val3') character set latin1 NOT NULL default '', `name` char(20) character set latin1 default 'O''Brien' COMMENT 'O''Brien as default', `c` int(11) NOT NULL default '0' COMMENT 'int column' ) TYPE=MyISAM CHARSET=latin1 COMMENT='it''s a table' show full columns from t1; Field Type Null Key Default Extra Privileges Comment -test_set set('val1','val2','val3') select,insert,update,references +test_set set('val1','val2','val3') character set latin1 select,insert,update,references name char(20) character set latin1 YES O'Brien select,insert,update,references O'Brien as default c int(11) 0 select,insert,update,references int column drop table t1; diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result index c0f0be246c9..51e11d259eb 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1626,13 +1626,13 @@ create table t1 (a enum (' ','a','b') not null); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` enum('','a','b') NOT NULL default '' + `a` enum('','a','b') character set latin1 NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 drop table t1; create table t1 (a enum (' ','a','b ') not null default 'b '); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` enum('','a','b') NOT NULL default 'b' + `a` enum('','a','b') character set latin1 NOT NULL default 'b' ) TYPE=MyISAM CHARSET=latin1 drop table t1; diff --git a/mysql-test/r/type_ranges.result b/mysql-test/r/type_ranges.result index 01149b68935..d0f964e4641 100644 --- a/mysql-test/r/type_ranges.result +++ b/mysql-test/r/type_ranges.result @@ -61,8 +61,8 @@ blob_col blob YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references mediumblob_col mediumblob select,insert,update,references longblob_col longblob select,insert,update,references -options enum('one','two','tree') MUL one select,insert,update,references -flags set('one','two','tree') select,insert,update,references +options enum('one','two','tree') character set latin1 MUL one select,insert,update,references +flags set('one','two','tree') character set latin1 select,insert,update,references show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 0 PRIMARY 1 auto A 0 NULL NULL BTREE @@ -190,8 +190,8 @@ date_time datetime YES NULL select,insert,update,references new_blob_col varchar(20) character set latin1 YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references mediumblob_col mediumblob select,insert,update,references -options enum('one','two','tree') MUL one select,insert,update,references -flags set('one','two','tree') select,insert,update,references +options enum('one','two','tree') character set latin1 MUL one select,insert,update,references +flags set('one','two','tree') character set latin1 select,insert,update,references new_field varchar(10) character set latin1 new select,insert,update,references show full columns from t2; Field Type Null Key Default Extra Privileges Comment @@ -216,8 +216,8 @@ date_time datetime YES NULL select,insert,update,references new_blob_col varchar(20) character set latin1 YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references mediumblob_col mediumblob select,insert,update,references -options enum('one','two','tree') one select,insert,update,references -flags set('one','two','tree') select,insert,update,references +options enum('one','two','tree') character set latin1 one select,insert,update,references +flags set('one','two','tree') character set latin1 select,insert,update,references new_field varchar(10) character set latin1 new select,insert,update,references select t1.auto,t2.auto from t1,t2 where t1.auto=t2.auto and ((t1.string<>t2.string and (t1.string is not null or t2.string is not null)) or (t1.tiny<>t2.tiny and (t1.tiny is not null or t2.tiny is not null)) or (t1.short<>t2.short and (t1.short is not null or t2.short is not null)) or (t1.medium<>t2.medium and (t1.medium is not null or t2.medium is not null)) or (t1.long_int<>t2.long_int and (t1.long_int is not null or t2.long_int is not null)) or (t1.longlong<>t2.longlong and (t1.longlong is not null or t2.longlong is not null)) or (t1.real_float<>t2.real_float and (t1.real_float is not null or t2.real_float is not null)) or (t1.real_double<>t2.real_double and (t1.real_double is not null or t2.real_double is not null)) or (t1.utiny<>t2.utiny and (t1.utiny is not null or t2.utiny is not null)) or (t1.ushort<>t2.ushort and (t1.ushort is not null or t2.ushort is not null)) or (t1.umedium<>t2.umedium and (t1.umedium is not null or t2.umedium is not null)) or (t1.ulong<>t2.ulong and (t1.ulong is not null or t2.ulong is not null)) or (t1.ulonglong<>t2.ulonglong and (t1.ulonglong is not null or t2.ulonglong is not null)) or (t1.time_stamp<>t2.time_stamp and (t1.time_stamp is not null or t2.time_stamp is not null)) or (t1.date_field<>t2.date_field and (t1.date_field is not null or t2.date_field is not null)) or (t1.time_field<>t2.time_field and (t1.time_field is not null or t2.time_field is not null)) or (t1.date_time<>t2.date_time and (t1.date_time is not null or t2.date_time is not null)) or (t1.new_blob_col<>t2.new_blob_col and (t1.new_blob_col is not null or t2.new_blob_col is not null)) or (t1.tinyblob_col<>t2.tinyblob_col and (t1.tinyblob_col is not null or t2.tinyblob_col is not null)) or (t1.mediumblob_col<>t2.mediumblob_col and (t1.mediumblob_col is not null or t2.mediumblob_col is not null)) or (t1.options<>t2.options and (t1.options is not null or t2.options is not null)) or (t1.flags<>t2.flags and (t1.flags is not null or t2.flags is not null)) or (t1.new_field<>t2.new_field and (t1.new_field is not null or t2.new_field is not null))); auto auto diff --git a/mysql-test/r/type_set.result b/mysql-test/r/type_set.result index b0ea1b69e59..256937c586a 100644 --- a/mysql-test/r/type_set.result +++ b/mysql-test/r/type_set.result @@ -3,13 +3,13 @@ create table t1 (a set (' ','a','b') not null); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` set('','a','b') NOT NULL default '' + `a` set('','a','b') character set latin1 NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 drop table t1; create table t1 (a set (' ','a','b ') not null default 'b '); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` set('','a','b') NOT NULL default 'b' + `a` set('','a','b') character set latin1 NOT NULL default 'b' ) TYPE=MyISAM CHARSET=latin1 drop table t1; diff --git a/sql/field.cc b/sql/field.cc index eca3ea05d45..8f61e053d27 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4906,7 +4906,7 @@ String *Field_enum::val_str(String *val_buffer __attribute__((unused)), else val_ptr->set((const char*) typelib->type_names[tmp-1], (uint) strlen(typelib->type_names[tmp-1]), - default_charset_info); + field_charset); return val_ptr; } @@ -4947,6 +4947,15 @@ void Field_enum::sql_type(String &res) const flag=1; } res.append(')'); + if (binary()) + { + res.append(" binary"); + } + else + { + res.append(" character set "); + res.append(field_charset->name); + } } @@ -5050,7 +5059,7 @@ String *Field_set::val_str(String *val_buffer, val_buffer->append(field_separator); String str(typelib->type_names[bitnr], (uint) strlen(typelib->type_names[bitnr]), - default_charset_info); + field_charset); val_buffer->append(str); } tmp>>=1; @@ -5074,6 +5083,15 @@ void Field_set::sql_type(String &res) const flag=1; } res.append(')'); + if (binary()) + { + res.append(" binary"); + } + else + { + res.append(" character set "); + res.append(field_charset->name); + } } /* returns 1 if the fields are equally defined */ @@ -5207,11 +5225,11 @@ Field *make_field(char *ptr, uint32 field_length, if (f_is_enum(pack_flag)) return new Field_enum(ptr,field_length,null_pos,null_bit, unireg_check, field_name, table, - pack_length, interval); + pack_length, interval, field_charset); else return new Field_set(ptr,field_length,null_pos,null_bit, unireg_check, field_name, table, - pack_length, interval); + pack_length, interval, field_charset); } } diff --git a/sql/field.h b/sql/field.h index 0c0b833f970..e4c1bd046ab 100644 --- a/sql/field.h +++ b/sql/field.h @@ -936,9 +936,10 @@ public: uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg,uint packlength_arg, - TYPELIB *typelib_arg) + TYPELIB *typelib_arg, + CHARSET_INFO *charset_arg) :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, table_arg, default_charset_info), + unireg_check_arg, field_name_arg, table_arg, charset_arg), packlength(packlength_arg),typelib(typelib_arg) { flags|=ENUM_FLAG; @@ -962,7 +963,6 @@ public: enum_field_types real_type() const { return FIELD_TYPE_ENUM; } virtual bool zero_pack() const { return 0; } bool optimize_range(uint idx) { return 0; } - bool binary() const { return 0; } bool eq_def(Field *field); }; @@ -973,11 +973,11 @@ public: uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg,uint32 packlength_arg, - TYPELIB *typelib_arg) + TYPELIB *typelib_arg, CHARSET_INFO *charset_arg) :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, table_arg, packlength_arg, - typelib_arg) + typelib_arg,charset_arg) { flags=(flags & ~ENUM_FLAG) | SET_FLAG; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 75d43e8c419..8b8da327b81 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -412,11 +412,15 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, case FIELD_TYPE_ENUM: sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) | FIELDFLAG_INTERVAL; + if (sql_field->charset->state & MY_CS_BINSORT) + sql_field->pack_flag|=FIELDFLAG_BINARY; sql_field->unireg_check=Field::INTERVAL_FIELD; break; case FIELD_TYPE_SET: sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) | FIELDFLAG_BITFIELD; + if (sql_field->charset->state & MY_CS_BINSORT) + sql_field->pack_flag|=FIELDFLAG_BINARY; sql_field->unireg_check=Field::BIT_FIELD; break; case FIELD_TYPE_DATE: // Rest of string types diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e2f97f5a080..83de03026f1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1064,13 +1064,13 @@ type: { $$=FIELD_TYPE_DECIMAL;} | NUMERIC_SYM float_options field_options { $$=FIELD_TYPE_DECIMAL;} - | ENUM {Lex->interval_list.empty();} '(' string_list ')' + | ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary { LEX *lex=Lex; lex->interval=typelib(lex->interval_list); $$=FIELD_TYPE_ENUM; } - | SET { Lex->interval_list.empty();} '(' string_list ')' + | SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary { LEX *lex=Lex; lex->interval=typelib(lex->interval_list);