summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorigor@olga.mysql.com <>2006-07-25 12:47:01 -0700
committerigor@olga.mysql.com <>2006-07-25 12:47:01 -0700
commit88e6b91096db9b3dca0b0940d66cc1cf0ffd0441 (patch)
treec5768cd1dd5ca300d3aa991cb7771ad4c6e29d60
parent69856b29b2b9c3c3e0f8adbcf6f130a0f2e1434e (diff)
parent9e9fb3e4e494bad69ce0ce668645e08d224809ee (diff)
downloadmariadb-git-88e6b91096db9b3dca0b0940d66cc1cf0ffd0441.tar.gz
Merge ibabaev@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into olga.mysql.com:/home/igor/mysql-5.0-opt
-rw-r--r--mysql-test/r/func_gconcat.result13
-rw-r--r--mysql-test/t/func_gconcat.test14
-rw-r--r--sql/item_sum.cc8
-rw-r--r--sql/sql_select.cc14
4 files changed, 46 insertions, 3 deletions
diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result
index d8a539da3fe..dc09a68682c 100644
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@ -641,3 +641,16 @@ select charset(group_concat(c1 order by c2)) from t1;
charset(group_concat(c1 order by c2))
latin1
drop table t1;
+CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a));
+SET GROUP_CONCAT_MAX_LEN = 20000000;
+INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
+INSERT INTO t1 SELECT a + 1, b FROM t1;
+SELECT a, CHAR_LENGTH(b) FROM t1;
+a CHAR_LENGTH(b)
+1 120000
+2 120000
+SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1;
+CHAR_LENGTH( GROUP_CONCAT(b) )
+240001
+SET GROUP_CONCAT_MAX_LEN = 1024;
+DROP TABLE t1;
diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test
index fbfdfa3b5d0..98c21986aa9 100644
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@ -433,3 +433,17 @@ create table t1 (c1 varchar(10), c2 int);
select charset(group_concat(c1 order by c2)) from t1;
drop table t1;
+#
+# Bug #16712: group_concat returns odd string instead of intended result
+#
+CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a));
+
+SET GROUP_CONCAT_MAX_LEN = 20000000;
+
+INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
+INSERT INTO t1 SELECT a + 1, b FROM t1;
+
+SELECT a, CHAR_LENGTH(b) FROM t1;
+SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1;
+SET GROUP_CONCAT_MAX_LEN = 1024;
+DROP TABLE t1;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 4d70debb966..b0caa5e1810 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -377,7 +377,13 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table,
case INT_RESULT:
return new Field_longlong(max_length,maybe_null,name,table,unsigned_flag);
case STRING_RESULT:
- if (max_length/collation.collation->mbmaxlen > 255 && convert_blob_length)
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
+ if (max_length/collation.collation->mbmaxlen > 255 &&
+ max_length/collation.collation->mbmaxlen < UINT_MAX16 &&
+ convert_blob_length)
return new Field_varstring(convert_blob_length, maybe_null,
name, table,
collation.collation);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a36f22b5101..bdcf3f327e5 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8034,7 +8034,12 @@ Field* create_tmp_field_from_field(THD *thd, Field* org_field,
{
Field *new_field;
- if (convert_blob_length && (org_field->flags & BLOB_FLAG))
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
+ if (convert_blob_length && convert_blob_length < UINT_MAX16 &&
+ (org_field->flags & BLOB_FLAG))
new_field= new Field_varstring(convert_blob_length,
org_field->maybe_null(),
org_field->field_name, table,
@@ -8116,8 +8121,13 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
if ((type= item->field_type()) == MYSQL_TYPE_DATETIME ||
type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE)
new_field= item->tmp_table_field_from_field_type(table);
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
else if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
- convert_blob_length)
+ item->max_length/item->collation.collation->mbmaxlen < UINT_MAX16
+ && convert_blob_length)
new_field= new Field_varstring(convert_blob_length, maybe_null,
item->name, table,
item->collation.collation);