From 624f855e948c374bda73f0594e4be9090dd90be0 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Wed, 23 Feb 2005 17:58:20 -0800 Subject: [PATCH] Make sure that warning message when GROUP_CONCAT() cuts values is also updated with the correct number of lines. (Bug #8681) --- mysql-test/r/join_outer.result | 19 +++++++++++++++++++ mysql-test/t/join_outer.test | 11 +++++++++++ sql/item_sum.cc | 23 +++++++++++++++-------- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index c045aa0d00a..1d15b2ba070 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -816,3 +816,22 @@ id text_id text_data 1 0 0-SV 2 10 10-SV DROP TABLE invoice, text_table; +set group_concat_max_len=5; +create table t1 (a int, b varchar(20)); +create table t2 (a int, c varchar(20)); +insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb"); +insert into t2 values (1,"cccccccccc"),(2,"dddddddddd"); +select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a; +group_concat(t1.b,t2.c) +aaaaa +bbbbb +Warnings: +Warning 1260 2 line(s) were cut by GROUP_CONCAT() +select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a; +group_concat(t1.b,t2.c) +aaaaa +bbbbb +Warnings: +Warning 1260 2 line(s) were cut by GROUP_CONCAT() +drop table t1, t2; +set group_concat_max_len=default; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index d177a68e685..62e76525d84 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -582,3 +582,14 @@ SELECT invoice.id, invoice.text_id, text_table.text_data WHERE (invoice.id LIKE '%' OR text_table.text_data LIKE '%'); DROP TABLE invoice, text_table; + +# Bug #8681: Bad warning message when group_concat() exceeds max length +set group_concat_max_len=5; +create table t1 (a int, b varchar(20)); +create table t2 (a int, c varchar(20)); +insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb"); +insert into t2 values (1,"cccccccccc"),(2,"dddddddddd"); +select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a; +select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a; +drop table t1, t2; +set group_concat_max_len=default; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 6bd2cc00b3e..7e9c5d09136 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1787,16 +1787,26 @@ Item_func_group_concat::Item_func_group_concat(THD *thd, void Item_func_group_concat::cleanup() { + THD *thd= current_thd; + DBUG_ENTER("Item_func_group_concat::cleanup"); Item_sum::cleanup(); + /* Adjust warning message to include total number of cut values */ + if (warning) + { + char warn_buff[MYSQL_ERRMSG_SIZE]; + sprintf(warn_buff, ER(ER_CUT_VALUE_GROUP_CONCAT), count_cut_values); + warning->set_msg(thd, warn_buff); + warning= 0; + } + /* Free table and tree if they belong to this item (if item have not pointer to original item from which was made copy => it own its objects ) */ if (!original) { - THD *thd= current_thd; if (table) { free_tmp_table(thd, table); @@ -1809,13 +1819,6 @@ void Item_func_group_concat::cleanup() tree_mode= 0; delete_tree(tree); } - if (warning) - { - char warn_buff[MYSQL_ERRMSG_SIZE]; - sprintf(warn_buff, ER(ER_CUT_VALUE_GROUP_CONCAT), count_cut_values); - warning->set_msg(thd, warn_buff); - warning= 0; - } } DBUG_VOID_RETURN; } @@ -2076,6 +2079,10 @@ String* Item_func_group_concat::val_str(String* str) if (null_value) return 0; if (count_cut_values && !warning) + /* + ER_CUT_VALUE_GROUP_CONCAT needs an argument, but this gets set in + Item_func_group_concat::cleanup(). + */ warning= push_warning(item_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_CUT_VALUE_GROUP_CONCAT, ER(ER_CUT_VALUE_GROUP_CONCAT));