More different syntaxes for (1) modifying the default charaset/collation

and for (2) converting the columns:

1.  ALTER TABLE t1 [DEFAULT] CHARACTER SET xxx [COLLATE yyy]
2.  ALTER TABLE t1 CONVERT TO CHARACTER SET xxx [COLLATE yyy]
parent 3bfbe6e0
......@@ -360,7 +360,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) character set koi8r default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t1 CHARACTER SET latin1;
alter table t1 CONVERT TO CHARACTER SET latin1, DEFAULT CHARACTER SET latin1;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
......@@ -379,15 +379,15 @@ show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`myblob` longblob,
`mytext` longtext character set latin1 collate latin1_general_cs
) ENGINE=MyISAM DEFAULT CHARSET=latin1
`mytext` longtext collate latin1_general_cs
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
alter table t1 character set latin2;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`myblob` longblob,
`mytext` longtext character set latin2
) ENGINE=MyISAM DEFAULT CHARSET=latin1
`mytext` longtext character set latin1 collate latin1_general_cs
) ENGINE=MyISAM DEFAULT CHARSET=latin2
drop table t1;
CREATE TABLE t1 (
Host varchar(16) binary NOT NULL default '',
......
......@@ -503,8 +503,8 @@ ALTER TABLE t1 CHARACTER SET latin1 COLLATE latin1_bin;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`latin1_f` char(32) character set latin1 collate latin1_bin default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
`latin1_f` char(32) collate latin1_bin default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin
SHOW FIELDS FROM t1;
Field Type Null Key Default Extra
latin1_f char(32) YES NULL
......
......@@ -214,7 +214,7 @@ select a,hex(a) from t1;
show create table t1;
alter table t1 DEFAULT CHARACTER SET latin1;
show create table t1;
alter table t1 CHARACTER SET latin1;
alter table t1 CONVERT TO CHARACTER SET latin1, DEFAULT CHARACTER SET latin1;
show create table t1;
alter table t1 DEFAULT CHARACTER SET cp1251;
show create table t1;
......
......@@ -115,6 +115,7 @@ static SYMBOL symbols[] = {
{ "COMPRESSED", SYM(COMPRESSED_SYM)},
{ "CONCURRENT", SYM(CONCURRENT)},
{ "CONSTRAINT", SYM(CONSTRAINT)},
{ "CONVERT", SYM(CONVERT_SYM)},
{ "CREATE", SYM(CREATE)},
{ "CROSS", SYM(CROSS)},
{ "CUBE", SYM(CUBE_SYM)},
......@@ -493,7 +494,6 @@ static SYMBOL sql_functions[] = {
{ "CONNECTION_ID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)},
{ "CONTAINS", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_contains)},
{ "CONV", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)},
{ "CONVERT", SYM(CONVERT_SYM)},
{ "COUNT", SYM(COUNT_SYM)},
{ "COS", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
{ "COT", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},
......
......@@ -1108,26 +1108,16 @@ create_table_option:
table_list->next=0;
lex->create_info.used_fields|= HA_CREATE_USED_UNION;
}
| DEFAULT charset opt_equal charset_name_or_default
| opt_default charset opt_equal charset_name_or_default
{
Lex->create_info.default_table_charset= $4;
Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
}
| charset opt_equal charset_name_or_default
| opt_default COLLATE_SYM opt_equal collation_name_or_default
{
Lex->create_info.table_charset= $3;
Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
}
| DEFAULT COLLATE_SYM opt_equal collation_name_or_default
{
Lex->create_info.table_charset= $4;
Lex->create_info.default_table_charset= $4;
Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
}
| COLLATE_SYM opt_equal collation_name_or_default
{
Lex->create_info.table_charset= $3;
Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
}
| INSERT_METHOD opt_equal merge_insert_types { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
{ Lex->create_info.data_file_name= $4.str; }
......@@ -1793,6 +1783,23 @@ alter_list_item:
lex->select_lex.db=$3->db.str;
lex->name= $3->table.str;
}
| CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
{
if (!$4)
{
THD *thd= YYTHD;
$4= thd->variables.collation_database;
}
$5= $5 ? $5 : $4;
if (!my_charset_same($4,$5))
{
net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
$5->name,$4->csname);
YYABORT;
}
Lex->create_info.table_charset= $5;
Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
}
| create_table_options_space_separated { Lex->simple_alter=0; }
| order_clause { Lex->simple_alter=0; };
......
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