Commit 721e9417 authored by unknown's avatar unknown

Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-maint

into  zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.1-maint


mysql-test/r/ctype_recoding.result:
  Auto merged
sql/sql_lex.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
mysql-test/t/ctype_recoding.test:
  manual merge.
sql/sql_lex.h:
  manual merge.
sql/sql_table.cc:
  manual merge.
parents 2e3e6ef1 5576ed8b
......@@ -248,3 +248,13 @@ select rpad(c1,3,'
rpad(c1,3,'') rpad('',3,c1)
drop table t1;
set names koi8r;
create table t1(a char character set cp1251 default _koi8r 0xFF);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) character set cp1251 default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(a char character set latin1 default _cp1251 0xFF);
ERROR 42000: Invalid default value for 'a'
......@@ -187,4 +187,16 @@ select rpad(c1,3,'
#select case c1 when '' then '' when '' then '' else 'c' end from t1;
#select export_set(5,c1,''), export_set(5,'',c1) from t1;
drop table t1;
#
# Bug 20695: problem with field default value's character set
#
set names koi8r;
create table t1(a char character set cp1251 default _koi8r 0xFF);
show create table t1;
drop table t1;
--error 1067
create table t1(a char character set latin1 default _cp1251 0xFF);
# End of 4.1 tests
......@@ -663,8 +663,9 @@ int MYSQLlex(void *arg, void *yythd)
*/
if ((yylval->lex_str.str[0]=='_') &&
(lex->charset=get_charset_by_csname(yylval->lex_str.str+1,
MY_CS_PRIMARY,MYF(0))))
(lex->underscore_charset=
get_charset_by_csname(yylval->lex_str.str + 1,
MY_CS_PRIMARY,MYF(0))))
return(UNDERSCORE_CHARSET);
return(result_state); // IDENT or IDENT_QUOTED
......
......@@ -895,7 +895,7 @@ typedef struct st_lex : public Query_tables_list
XID *xid;
gptr yacc_yyss,yacc_yyvs;
THD *thd;
CHARSET_INFO *charset;
CHARSET_INFO *charset, *underscore_charset;
/* store original leaf_tables for INSERT SELECT and PS/SP */
TABLE_LIST *leaf_tables_insert;
/* Position (first character index) of SELECT of CREATE VIEW statement */
......
......@@ -2224,6 +2224,40 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
DBUG_RETURN(-1);
}
/*
Convert the default value character
set into the column character set if necessary.
*/
if (sql_field->def &&
savecs != sql_field->def->collation.collation &&
(sql_field->sql_type == FIELD_TYPE_VAR_STRING ||
sql_field->sql_type == FIELD_TYPE_STRING ||
sql_field->sql_type == FIELD_TYPE_SET ||
sql_field->sql_type == FIELD_TYPE_ENUM))
{
Item_arena backup_arena;
bool need_to_change_arena=
!thd->current_arena->is_conventional_execution();
if (need_to_change_arena)
{
/* Assert that we don't do that at every PS execute */
DBUG_ASSERT(thd->current_arena->is_first_stmt_execute());
thd->set_n_backup_item_arena(thd->current_arena, &backup_arena);
}
sql_field->def= sql_field->def->safe_charset_converter(savecs);
if (need_to_change_arena)
thd->restore_backup_item_arena(thd->current_arena, &backup_arena);
if (sql_field->def == NULL)
{
/* Could not convert */
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
DBUG_RETURN(-1);
}
}
if (sql_field->sql_type == FIELD_TYPE_SET ||
sql_field->sql_type == FIELD_TYPE_ENUM)
{
......@@ -2285,35 +2319,6 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
sql_field->interval_list.empty(); // Don't need interval_list anymore
}
/*
Convert the default value from client character
set into the column character set if necessary.
*/
if (sql_field->def && cs != sql_field->def->collation.collation)
{
Query_arena backup_arena;
bool need_to_change_arena= !thd->stmt_arena->is_conventional();
if (need_to_change_arena)
{
/* Asser that we don't do that at every PS execute */
DBUG_ASSERT(thd->stmt_arena->is_first_stmt_execute() ||
thd->stmt_arena->is_first_sp_execute());
thd->set_n_backup_active_arena(thd->stmt_arena, &backup_arena);
}
sql_field->def= sql_field->def->safe_charset_converter(cs);
if (need_to_change_arena)
thd->restore_active_arena(thd->stmt_arena, &backup_arena);
if (sql_field->def == NULL)
{
/* Could not convert */
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
DBUG_RETURN(-1);
}
}
if (sql_field->sql_type == FIELD_TYPE_SET)
{
uint32 field_length;
......
......@@ -8902,7 +8902,7 @@ text_literal:
| NCHAR_STRING
{ $$= new Item_string($1.str,$1.length,national_charset_info); }
| UNDERSCORE_CHARSET TEXT_STRING
{ $$ = new Item_string($2.str,$2.length,Lex->charset); }
{ $$ = new Item_string($2.str,$2.length,Lex->underscore_charset); }
| text_literal TEXT_STRING_literal
{ ((Item_string*) $1)->append($2.str,$2.length); }
;
......@@ -8980,7 +8980,7 @@ literal:
(String*) 0;
$$= new Item_string(str ? str->ptr() : "",
str ? str->length() : 0,
Lex->charset);
Lex->underscore_charset);
}
| UNDERSCORE_CHARSET BIN_NUM
{
......
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