Commit af9740d0 authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

func_gconcat.result, func_gconcat.test:

  Added test cases for bug #12863.
item_sum.cc, item_sum.h:
  Fixed bug #12863.
  Added a flag to Item_func_group_concat set to FALSE after
  concatenation of the first element of a group.
parent 81948e62
......@@ -560,3 +560,23 @@ group_concat('x')
NULL
1
drop table t1;
CREATE TABLE t1 (id int, a varchar(9));
INSERT INTO t1 VALUES
(2, ''), (1, ''), (2, 'x'), (1, 'y'), (3, 'z'), (3, '');
SELECT GROUP_CONCAT(a) FROM t1;
GROUP_CONCAT(a)
,,x,y,z,
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1;
GROUP_CONCAT(a ORDER BY a)
,,,x,y,z
SELECT GROUP_CONCAT(a) FROM t1 GROUP BY id;
GROUP_CONCAT(a)
,y
,x
z,
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY id;
GROUP_CONCAT(a ORDER BY a)
,y
,x
,z
DROP TABLE t1;
......@@ -356,4 +356,20 @@ select * from (select group_concat(a) from t1) t2;
select group_concat('x') UNION ALL select 1;
drop table t1;
#
# Bug #12863 : missing separators after first empty cancatanated elements
#
CREATE TABLE t1 (id int, a varchar(9));
INSERT INTO t1 VALUES
(2, ''), (1, ''), (2, 'x'), (1, 'y'), (3, 'z'), (3, '');
SELECT GROUP_CONCAT(a) FROM t1;
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1;
SELECT GROUP_CONCAT(a) FROM t1 GROUP BY id;
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY id;
DROP TABLE t1;
# End of 4.1 tests
......@@ -1664,7 +1664,9 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
char buff[MAX_FIELD_WIDTH];
String tmp((char *)&buff,sizeof(buff),default_charset_info), tmp2;
if (item->result.length())
if (item->no_appended)
item->no_appended= FALSE;
else
item->result.append(*item->separator);
tmp.length(0);
......@@ -1856,6 +1858,7 @@ void Item_func_group_concat::clear()
result.copy();
null_value= TRUE;
warning_for_row= FALSE;
no_appended= TRUE;
if (tree_mode)
reset_tree(tree);
}
......@@ -1898,8 +1901,7 @@ bool Item_func_group_concat::add()
void Item_func_group_concat::reset_field()
{
if (tree_mode)
reset_tree(tree);
DBUG_ASSERT(0);
}
......
......@@ -709,6 +709,7 @@ class Item_func_group_concat : public Item_sum
uint arg_count_field;
uint field_list_offset;
uint count_cut_values;
bool no_appended;
/*
Following is 0 normal object and pointer to original one for copy
(to correctly free resources)
......
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