summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.(none)>2006-03-02 20:49:10 -0500
committerunknown <cmiller@zippy.(none)>2006-03-02 20:49:10 -0500
commitedbea609a0552c769e5343bf879b2aa40769e198 (patch)
tree8f19d57643c3f4733424c1e6c8c438bac0107ec1
parentd25f1055ee2506fd0b8989d6a1246190d0739514 (diff)
downloadmariadb-git-edbea609a0552c769e5343bf879b2aa40769e198.tar.gz
Expanding a binary field should result in 0x00-filled positions, not 0x20
(ASCII space). For Bug#16857. sql/field_conv.cc: Bug#16857: Do not expand BINARY fields as if they are strings (which presumably /should/ be filled with spaces). Instead, fill BINARY fields with 0x00 bytes.
-rw-r--r--mysql-test/r/binary.result19
-rw-r--r--mysql-test/t/binary.test12
-rw-r--r--sql/field_conv.cc18
3 files changed, 48 insertions, 1 deletions
diff --git a/mysql-test/r/binary.result b/mysql-test/r/binary.result
index a8d6c3bf411..c5673d1c00d 100644
--- a/mysql-test/r/binary.result
+++ b/mysql-test/r/binary.result
@@ -141,3 +141,22 @@ t1 CREATE TABLE `t1` (
`a` binary(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
+create table t1 (col1 binary(4));
+insert into t1 values ('a'),('a ');
+select hex(col1) from t1;
+hex(col1)
+61000000
+61200000
+alter table t1 modify col1 binary(10);
+select hex(col1) from t1;
+hex(col1)
+61000000000000000000
+61200000000000000000
+insert into t1 values ('b'),('b ');
+select hex(col1) from t1;
+hex(col1)
+61000000000000000000
+61200000000000000000
+62000000000000000000
+62200000000000000000
+drop table t1;
diff --git a/mysql-test/t/binary.test b/mysql-test/t/binary.test
index 1ac0cfebb28..4ab6ee9eaf1 100644
--- a/mysql-test/t/binary.test
+++ b/mysql-test/t/binary.test
@@ -89,3 +89,15 @@ show create table t1;
drop table t1;
# End of 4.1 tests
+
+#
+# Bug#16857
+#
+create table t1 (col1 binary(4));
+insert into t1 values ('a'),('a ');
+select hex(col1) from t1;
+alter table t1 modify col1 binary(10);
+select hex(col1) from t1;
+insert into t1 values ('b'),('b ');
+select hex(col1) from t1;
+drop table t1;
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index bbe2dbe5e9f..895f022624c 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -379,6 +379,16 @@ static void do_cut_string_complex(Copy_field *copy)
+static void do_expand_binary(Copy_field *copy)
+{
+ CHARSET_INFO *cs= copy->from_field->charset();
+ memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
+ cs->cset->fill(cs, copy->to_ptr+copy->from_length,
+ copy->to_length-copy->from_length, '\0');
+}
+
+
+
static void do_expand_string(Copy_field *copy)
{
CHARSET_INFO *cs= copy->from_field->charset();
@@ -583,7 +593,13 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
return (from->charset()->mbmaxlen == 1 ?
do_cut_string : do_cut_string_complex);
else if (to_length > from_length)
- return do_expand_string;
+ {
+ if ((to->flags & BINARY_FLAG) != 0)
+ return do_expand_binary;
+ else
+ return do_expand_string;
+ }
+
}
else if (to->real_type() != from->real_type() ||
to_length != from_length ||