From 41a61e84d724e48f6d1e026e7f79469b55ac230c Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 10 Dec 2004 00:17:43 +0200 Subject: [PATCH] A fix for a crashing bug #7101, which occures when the expression involving LEFT() function is used in GROUP BY field. mysql-test/r/func_str.result: A result for bug #7101 test case mysql-test/t/func_str.test: Test case for bug #7101 --- mysql-test/r/func_str.result | 6 ++++++ mysql-test/t/func_str.test | 8 ++++++++ sql/item_strfunc.cc | 5 +++-- sql/item_strfunc.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 8d49d55be39..0e98f304d89 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -685,3 +685,9 @@ drop table t1; select left(1234, 3) + 0; left(1234, 3) + 0 123 +create table t1 (a int not null primary key, b varchar(40), c datetime); +insert into t1 (a,b,c) values (1,'Tom',now()),(2,'ball games',now()), (3,'Basil',now()), (4,'Dean',now()),(5,'Ellis',now()), (6,'Serg',now()), (7,'Sergei',now()),(8,'Georg',now()),(9,'Salle',now()),(10,'Sinisa',now()); +select count(*) as total, left(c,10) as reg from t1 group by reg order by reg desc limit 0,12; +total reg +10 2004-12-10 +drop table t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index d5a3e80c417..2934a9733a7 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -421,3 +421,11 @@ drop table t1; # select left(1234, 3) + 0; + +# +# Bug #7101: bug with LEFT() when used as a field in GROUP BY aggregation +# +create table t1 (a int not null primary key, b varchar(40), c datetime); +insert into t1 (a,b,c) values (1,'Tom',now()),(2,'ball games',now()), (3,'Basil',now()), (4,'Dean',now()),(5,'Ellis',now()), (6,'Serg',now()), (7,'Sergei',now()),(8,'Georg',now()),(9,'Salle',now()),(10,'Sinisa',now()); +select count(*) as total, left(c,10) as reg from t1 group by reg order by reg desc limit 0,12; +drop table t1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 893126b7fe6..7fc5e51621e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -955,8 +955,9 @@ String *Item_func_left::val_str(String *str) if (res->length() <= (uint) length || res->length() <= (char_pos= res->charpos(length))) return res; - str_value.set(*res, 0, char_pos); - return &str_value; + + tmp_value.set(*res, 0, char_pos); + return &tmp_value; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index afe03c31345..8efe60bbd89 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -162,6 +162,7 @@ public: class Item_func_left :public Item_str_func { + String tmp_value; public: Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {} String *val_str(String *);