summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbar@bar.mysql.r18.ru <>2003-03-04 12:33:52 +0400
committerbar@bar.mysql.r18.ru <>2003-03-04 12:33:52 +0400
commit6cbbbd69485ec0547db127e439c113481d31f1d5 (patch)
tree3667f04b4e731d43aed2a2e5149a8a1e259518bd
parentc4dc670d6127cc8129ce57a2bc3ab76538776ad4 (diff)
downloadmariadb-git-6cbbbd69485ec0547db127e439c113481d31f1d5.tar.gz
Fix for SHOW, it didn't display CHARACTER SET and COLLATE clause
for binary collations
-rw-r--r--mysql-test/r/ctype_collate.result27
-rw-r--r--mysql-test/t/ctype_collate.test15
-rw-r--r--sql/field.cc19
-rw-r--r--sql/field.h11
-rw-r--r--sql/sql_show.cc2
5 files changed, 56 insertions, 18 deletions
diff --git a/mysql-test/r/ctype_collate.result b/mysql-test/r/ctype_collate.result
index cf93de4b7c6..4217bd5de23 100644
--- a/mysql-test/r/ctype_collate.result
+++ b/mysql-test/r/ctype_collate.result
@@ -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;
diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test
index 741db4d55e7..26a18c5f279 100644
--- a/mysql-test/t/ctype_collate.test
+++ b/mysql-test/t/ctype_collate.test
@@ -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;
diff --git a/sql/field.cc b/sql/field.cc
index b96b987ec90..5a8cbdfbb1c 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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();
diff --git a/sql/field.h b/sql/field.h
index 04225158270..37d194ac372 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -160,8 +160,6 @@ public:
{ 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 @@ public:
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 @@ public:
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;
};
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index fd7127bcd00..9c2280768da 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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);