Commit 440db4c1 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

ENUM/SET fields now have charset too

parent ff83d1e4
...@@ -93,13 +93,13 @@ c int not null comment 'int column' ...@@ -93,13 +93,13 @@ c int not null comment 'int column'
show create table t1 ; show create table t1 ;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( 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', `name` char(20) character set latin1 default 'O''Brien' COMMENT 'O''Brien as default',
`c` int(11) NOT NULL default '0' COMMENT 'int column' `c` int(11) NOT NULL default '0' COMMENT 'int column'
) TYPE=MyISAM CHARSET=latin1 COMMENT='it''s a table' ) TYPE=MyISAM CHARSET=latin1 COMMENT='it''s a table'
show full columns from t1; show full columns from t1;
Field Type Null Key Default Extra Privileges Comment 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 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 c int(11) 0 select,insert,update,references int column
drop table t1; drop table t1;
......
...@@ -1626,13 +1626,13 @@ create table t1 (a enum (' ','a','b') not null); ...@@ -1626,13 +1626,13 @@ create table t1 (a enum (' ','a','b') not null);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( 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 ) TYPE=MyISAM CHARSET=latin1
drop table t1; drop table t1;
create table t1 (a enum (' ','a','b ') not null default 'b '); create table t1 (a enum (' ','a','b ') not null default 'b ');
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( 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 ) TYPE=MyISAM CHARSET=latin1
drop table t1; drop table t1;
...@@ -61,8 +61,8 @@ blob_col blob YES NULL select,insert,update,references ...@@ -61,8 +61,8 @@ blob_col blob YES NULL select,insert,update,references
tinyblob_col tinyblob YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references
mediumblob_col mediumblob select,insert,update,references mediumblob_col mediumblob select,insert,update,references
longblob_col longblob select,insert,update,references longblob_col longblob select,insert,update,references
options enum('one','two','tree') MUL one select,insert,update,references options enum('one','two','tree') character set latin1 MUL one select,insert,update,references
flags set('one','two','tree') select,insert,update,references flags set('one','two','tree') character set latin1 select,insert,update,references
show keys from t1; show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment 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 t1 0 PRIMARY 1 auto A 0 NULL NULL BTREE
...@@ -190,8 +190,8 @@ date_time datetime YES NULL select,insert,update,references ...@@ -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 new_blob_col varchar(20) character set latin1 YES NULL select,insert,update,references
tinyblob_col tinyblob YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references
mediumblob_col mediumblob select,insert,update,references mediumblob_col mediumblob select,insert,update,references
options enum('one','two','tree') MUL one select,insert,update,references options enum('one','two','tree') character set latin1 MUL one select,insert,update,references
flags set('one','two','tree') 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 new_field varchar(10) character set latin1 new select,insert,update,references
show full columns from t2; show full columns from t2;
Field Type Null Key Default Extra Privileges Comment Field Type Null Key Default Extra Privileges Comment
...@@ -216,8 +216,8 @@ date_time datetime YES NULL select,insert,update,references ...@@ -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 new_blob_col varchar(20) character set latin1 YES NULL select,insert,update,references
tinyblob_col tinyblob YES NULL select,insert,update,references tinyblob_col tinyblob YES NULL select,insert,update,references
mediumblob_col mediumblob select,insert,update,references mediumblob_col mediumblob select,insert,update,references
options enum('one','two','tree') one select,insert,update,references options enum('one','two','tree') character set latin1 one select,insert,update,references
flags set('one','two','tree') 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 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))); 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 auto auto
......
...@@ -3,13 +3,13 @@ create table t1 (a set (' ','a','b') not null); ...@@ -3,13 +3,13 @@ create table t1 (a set (' ','a','b') not null);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( 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 ) TYPE=MyISAM CHARSET=latin1
drop table t1; drop table t1;
create table t1 (a set (' ','a','b ') not null default 'b '); create table t1 (a set (' ','a','b ') not null default 'b ');
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( 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 ) TYPE=MyISAM CHARSET=latin1
drop table t1; drop table t1;
...@@ -4906,7 +4906,7 @@ String *Field_enum::val_str(String *val_buffer __attribute__((unused)), ...@@ -4906,7 +4906,7 @@ String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
else else
val_ptr->set((const char*) typelib->type_names[tmp-1], val_ptr->set((const char*) typelib->type_names[tmp-1],
(uint) strlen(typelib->type_names[tmp-1]), (uint) strlen(typelib->type_names[tmp-1]),
default_charset_info); field_charset);
return val_ptr; return val_ptr;
} }
...@@ -4947,6 +4947,15 @@ void Field_enum::sql_type(String &res) const ...@@ -4947,6 +4947,15 @@ void Field_enum::sql_type(String &res) const
flag=1; flag=1;
} }
res.append(')'); 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, ...@@ -5050,7 +5059,7 @@ String *Field_set::val_str(String *val_buffer,
val_buffer->append(field_separator); val_buffer->append(field_separator);
String str(typelib->type_names[bitnr], String str(typelib->type_names[bitnr],
(uint) strlen(typelib->type_names[bitnr]), (uint) strlen(typelib->type_names[bitnr]),
default_charset_info); field_charset);
val_buffer->append(str); val_buffer->append(str);
} }
tmp>>=1; tmp>>=1;
...@@ -5074,6 +5083,15 @@ void Field_set::sql_type(String &res) const ...@@ -5074,6 +5083,15 @@ void Field_set::sql_type(String &res) const
flag=1; flag=1;
} }
res.append(')'); 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 */ /* returns 1 if the fields are equally defined */
...@@ -5207,11 +5225,11 @@ Field *make_field(char *ptr, uint32 field_length, ...@@ -5207,11 +5225,11 @@ Field *make_field(char *ptr, uint32 field_length,
if (f_is_enum(pack_flag)) if (f_is_enum(pack_flag))
return new Field_enum(ptr,field_length,null_pos,null_bit, return new Field_enum(ptr,field_length,null_pos,null_bit,
unireg_check, field_name, table, unireg_check, field_name, table,
pack_length, interval); pack_length, interval, field_charset);
else else
return new Field_set(ptr,field_length,null_pos,null_bit, return new Field_set(ptr,field_length,null_pos,null_bit,
unireg_check, field_name, table, unireg_check, field_name, table,
pack_length, interval); pack_length, interval, field_charset);
} }
} }
......
...@@ -936,9 +936,10 @@ class Field_enum :public Field_str { ...@@ -936,9 +936,10 @@ class Field_enum :public Field_str {
uchar null_bit_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg, enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg,uint packlength_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, :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) packlength(packlength_arg),typelib(typelib_arg)
{ {
flags|=ENUM_FLAG; flags|=ENUM_FLAG;
...@@ -962,7 +963,6 @@ class Field_enum :public Field_str { ...@@ -962,7 +963,6 @@ class Field_enum :public Field_str {
enum_field_types real_type() const { return FIELD_TYPE_ENUM; } enum_field_types real_type() const { return FIELD_TYPE_ENUM; }
virtual bool zero_pack() const { return 0; } virtual bool zero_pack() const { return 0; }
bool optimize_range(uint idx) { return 0; } bool optimize_range(uint idx) { return 0; }
bool binary() const { return 0; }
bool eq_def(Field *field); bool eq_def(Field *field);
}; };
...@@ -973,11 +973,11 @@ class Field_set :public Field_enum { ...@@ -973,11 +973,11 @@ class Field_set :public Field_enum {
uchar null_bit_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg, enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg,uint32 packlength_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, :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, unireg_check_arg, field_name_arg,
table_arg, packlength_arg, table_arg, packlength_arg,
typelib_arg) typelib_arg,charset_arg)
{ {
flags=(flags & ~ENUM_FLAG) | SET_FLAG; flags=(flags & ~ENUM_FLAG) | SET_FLAG;
} }
......
...@@ -412,11 +412,15 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -412,11 +412,15 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
case FIELD_TYPE_ENUM: case FIELD_TYPE_ENUM:
sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) | sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
FIELDFLAG_INTERVAL; FIELDFLAG_INTERVAL;
if (sql_field->charset->state & MY_CS_BINSORT)
sql_field->pack_flag|=FIELDFLAG_BINARY;
sql_field->unireg_check=Field::INTERVAL_FIELD; sql_field->unireg_check=Field::INTERVAL_FIELD;
break; break;
case FIELD_TYPE_SET: case FIELD_TYPE_SET:
sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) | sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
FIELDFLAG_BITFIELD; FIELDFLAG_BITFIELD;
if (sql_field->charset->state & MY_CS_BINSORT)
sql_field->pack_flag|=FIELDFLAG_BINARY;
sql_field->unireg_check=Field::BIT_FIELD; sql_field->unireg_check=Field::BIT_FIELD;
break; break;
case FIELD_TYPE_DATE: // Rest of string types case FIELD_TYPE_DATE: // Rest of string types
......
...@@ -1064,13 +1064,13 @@ type: ...@@ -1064,13 +1064,13 @@ type:
{ $$=FIELD_TYPE_DECIMAL;} { $$=FIELD_TYPE_DECIMAL;}
| NUMERIC_SYM float_options field_options | NUMERIC_SYM float_options field_options
{ $$=FIELD_TYPE_DECIMAL;} { $$=FIELD_TYPE_DECIMAL;}
| ENUM {Lex->interval_list.empty();} '(' string_list ')' | ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->interval=typelib(lex->interval_list); lex->interval=typelib(lex->interval_list);
$$=FIELD_TYPE_ENUM; $$=FIELD_TYPE_ENUM;
} }
| SET { Lex->interval_list.empty();} '(' string_list ')' | SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->interval=typelib(lex->interval_list); lex->interval=typelib(lex->interval_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment