Commit 96636daf authored by unknown's avatar unknown

proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly.

note: bar asked me to use res.charset in ::sql_type() functions to be more consistent.


mysql-test/r/type_enum.result:
  proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly
mysql-test/t/type_enum.test:
  proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly
sql/field.cc:
  proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly
sql/sql_show.cc:
  proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly
sql/table.cc:
  proper fix for the bug #2077: accented characters in enum/defaul values are reported incorrectly
parent 029e30b4
......@@ -1636,6 +1636,7 @@ t1 CREATE TABLE `t1` (
`a` enum('','a','b') NOT NULL default 'b'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set names latin1;
create table t1 (a enum(0xE4, '1', '2') not null default 0xE4);
show columns from t1;
Field Type Null Key Default Extra
......@@ -1643,6 +1644,6 @@ a enum('
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` enum('','1','2') NOT NULL default '?'
`a` enum('','1','2') NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
......@@ -29,8 +29,8 @@ drop table t1;
# Bug #2077
#
set names latin1;
create table t1 (a enum(0xE4, '1', '2') not null default 0xE4);
show columns from t1;
# should be fixed ASAP
show create table t1;
drop table t1;
......@@ -5192,16 +5192,21 @@ void Field_enum::sort_string(char *to,uint length __attribute__((unused)))
void Field_enum::sql_type(String &res) const
{
char buffer[255];
String enum_item(buffer, sizeof(buffer), res.charset());
res.length(0);
res.append("enum(");
bool flag=0;
for (const char **pos=typelib->type_names; *pos ; pos++)
for (const char **pos= typelib->type_names; *pos; pos++)
{
if (flag)
res.append(',');
append_unescaped(&res, *pos, strlen(*pos));
flag=1;
/* convert to res.charset() == utf8, then quote */
enum_item.copy(*pos, strlen(*pos), charset(), res.charset());
append_unescaped(&res, enum_item.ptr(), enum_item.length());
flag= 1;
}
res.append(')');
}
......@@ -5300,16 +5305,21 @@ String *Field_set::val_str(String *val_buffer,
void Field_set::sql_type(String &res) const
{
char buffer[255];
String set_item(buffer, sizeof(buffer), res.charset());
res.length(0);
res.append("set(");
bool flag=0;
for (const char **pos=typelib->type_names; *pos ; pos++)
for (const char **pos= typelib->type_names; *pos; pos++)
{
if (flag)
res.append(',');
append_unescaped(&res, *pos, strlen(*pos));
flag=1;
/* convert to res.charset() == utf8, then quote */
set_item.copy(*pos, strlen(*pos), charset(), res.charset());
append_unescaped(&res, set_item.ptr(), set_item.length());
flag= 1;
}
res.append(')');
}
......
......@@ -688,14 +688,14 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
{
byte *pos;
uint flags=field->flags;
String type(tmp,sizeof(tmp), field->charset());
String type(tmp,sizeof(tmp), system_charset_info);
uint col_access;
bool null_default_value=0;
protocol->prepare_for_resend();
protocol->store(field->field_name, system_charset_info);
field->sql_type(type);
protocol->store(type.ptr(), type.length(), type.charset());
protocol->store(type.ptr(), type.length(), system_charset_info);
if (verbose)
protocol->store(field->has_charset() ? field->charset()->name : "NULL",
system_charset_info);
......@@ -1117,7 +1117,13 @@ store_create_info(THD *thd, TABLE *table, String *packet)
type.set(tmp, sizeof(tmp), field->charset());
field->val_str(&type,&type);
if (type.length())
append_unescaped(packet, type.ptr(), type.length());
{
String def_val;
/* convert to system_charset_info == utf8 */
def_val.copy(type.ptr(), type.length(), field->charset(),
system_charset_info);
append_unescaped(packet, def_val.ptr(), def_val.length());
}
else
packet->append("''",2);
}
......
......@@ -1058,9 +1058,21 @@ ulong next_io_size(register ulong pos)
} /* next_io_size */
/* Store in String an SQL quoted string */
/*
Store an SQL quoted string.
SYNOPSIS
append_unescaped()
res result String
pos string to be quoted
length it's length
NOTE
This function works correctly with utf8 or single-byte charset strings.
May fail with some multibyte charsets though.
*/
void append_unescaped(String *res,const char *pos, uint length)
void append_unescaped(String *res, const char *pos, uint length)
{
const char *end= pos+length;
res->append('\'');
......
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