Commit 6cbbbd69 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

Fix for SHOW, it didn't display CHARACTER SET and COLLATE clause

for binary collations
parent c4dc670d
......@@ -483,4 +483,31 @@ Z
z
SELECT DISTINCT latin1_f COLLATE koi8r FROM t1;
COLLATION 'koi8r' is not valid for CHARACTER SET 'latin1'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`latin1_f` char(32) NOT NULL default ''
) TYPE=MyISAM CHARSET=latin1
SHOW FIELDS FROM t1;
Field Type Collation Null Key Default Extra
latin1_f char(32) latin1
ALTER TABLE t1 CHANGE latin1_f
latin1_f CHAR(32) 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
) TYPE=MyISAM CHARSET=latin1
SHOW FIELDS FROM t1;
Field Type Collation Null Key Default Extra
latin1_f char(32) character set latin1 latin1_bin YES NULL
ALTER TABLE t1 CHARACTER SET latin1 COLLATE latin1_bin;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`latin1_f` char(32) collate latin1_bin default NULL
) TYPE=MyISAM CHARSET=latin1 COLLATE=latin1_bin
SHOW FIELDS FROM t1;
Field Type Collation Null Key Default Extra
latin1_f char(32) latin1_bin YES NULL
DROP TABLE t1;
......@@ -112,4 +112,19 @@ SELECT DISTINCT latin1_f COLLATE koi8r FROM t1;
--FROM t1
--HAVING (_latin1'Mu"ller' COLLATE latin1_de) = k
#
# Check that SHOW displays COLLATE clause
#
SHOW CREATE TABLE t1;
SHOW FIELDS FROM t1;
ALTER TABLE t1 CHANGE latin1_f
latin1_f CHAR(32) CHARACTER SET latin1 COLLATE latin1_bin;
SHOW CREATE TABLE t1;
SHOW FIELDS FROM t1;
ALTER TABLE t1 CHARACTER SET latin1 COLLATE latin1_bin;
SHOW CREATE TABLE t1;
SHOW FIELDS FROM t1;
DROP TABLE t1;
......@@ -248,7 +248,7 @@ void Field_str::make_field(Send_field *field)
void Field_str::add_binary_or_charset(String &res) const
{
if (binary())
if (charset() == &my_charset_bin)
res.append(" binary");
else if (field_charset != table->table_charset &&
!(current_thd->variables.sql_mode & MODE_NO_FIELD_OPTIONS) &&
......@@ -3875,13 +3875,18 @@ void Field_datetime::sql_type(String &res) const
/* Copy a string and fill with space */
static bool use_conversion(CHARSET_INFO *cs1, CHARSET_INFO *cs2)
{
return (cs1 != &my_charset_bin) && (cs2 != &my_charset_bin) && (cs1!=cs2);
}
int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
{
int error= 0;
char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin);
/* Convert character set if nesessary */
if ((cs != field_charset) && (cs!=&my_charset_bin) && (!binary()))
if (use_conversion(cs, field_charset))
{
tmpstr.copy(from, length, cs, field_charset);
from= tmpstr.ptr();
......@@ -4063,7 +4068,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin);
/* Convert character set if nesessary */
if ((cs != field_charset) && (cs!=&my_charset_bin) && (!binary()))
if (use_conversion(cs, field_charset))
{
tmpstr.copy(from, length, cs, field_charset);
from= tmpstr.ptr();
......@@ -4380,7 +4385,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin);
/* Convert character set if nesessary */
if ((cs != field_charset) && (cs!=&my_charset_bin) && (!binary()))
if (use_conversion(cs, field_charset))
{
tmpstr.copy(from, length, cs, field_charset);
from= tmpstr.ptr();
......@@ -4627,7 +4632,7 @@ void Field_blob::sql_type(String &res) const
case 4: str="long"; length=4; break;
}
res.set_latin1(str,length);
if (binary())
if (charset() == &my_charset_bin)
res.append("blob");
else
{
......@@ -4857,7 +4862,7 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin);
/* Convert character set if nesessary */
if ((cs != field_charset) && (cs!=&my_charset_bin) && (!binary()))
if (use_conversion(cs, field_charset))
{
tmpstr.copy(from, length, cs, field_charset);
from= tmpstr.ptr();
......@@ -5072,7 +5077,7 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin);
/* Convert character set if nesessary */
if ((cs != field_charset) && (cs!=&my_charset_bin) && (!binary()))
if (use_conversion(cs, field_charset))
{
tmpstr.copy(from, length, cs, field_charset);
from= tmpstr.ptr();
......
......@@ -160,8 +160,6 @@ class Field
{ get_image(buff,length,cs); }
virtual void set_key_image(char *buff,uint length, CHARSET_INFO *cs)
{ set_image(buff,length,cs); }
inline int cmp_image(char *buff,uint length)
{ return memcmp(ptr,buff,length); }
inline longlong val_int_offset(uint row_offset)
{
ptr+=row_offset;
......@@ -265,7 +263,7 @@ class Field_str :public Field {
unireg_check_arg, field_name_arg, table_arg)
{
field_charset=charset;
if (binary())
if (charset->state & MY_CS_BINSORT)
flags|=BINARY_FLAG;
}
Item_result result_type () const { return STRING_RESULT; }
......@@ -277,13 +275,6 @@ class Field_str :public Field {
void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; }
inline int cmp_image(char *buff,uint length)
{
if (binary())
return memcmp(ptr,buff,length);
else
return my_strncasecmp(field_charset,ptr,buff,length);
}
friend class create_field;
};
......
......@@ -1074,7 +1074,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
For string types dump collation name only if
collation is not primary for the given charset
*/
if (!field->binary() && !(field->charset()->state & MY_CS_PRIMARY) &&
if (!(field->charset()->state & MY_CS_PRIMARY) &&
!limited_mysql_mode && !foreign_db_mode)
{
packet->append(" collate ", 9);
......
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