summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2006-03-02 14:54:04 +0100
committerunknown <pem@mysql.com>2006-03-02 14:54:04 +0100
commitd25f1055ee2506fd0b8989d6a1246190d0739514 (patch)
treea7840376ad020d0f7c4277e6d8d827d19113d851
parentf07aecfe5f979c905170001dd797656b050c622f (diff)
downloadmariadb-git-d25f1055ee2506fd0b8989d6a1246190d0739514.tar.gz
Fixed BUG#17476: Stored procedure not returning data when it is called first
time per connection Removed const_string() method from Item_string (it was only used in one place, in a bad way). Defer possible SP variable, and access data directly instead, in date_format item. mysql-test/r/sp.result: Updated results for new test (BUG#17476). mysql-test/t/sp.test: New test case (BUG#17476) sql/item.h: Removed const_string() from Item_string. It was only used in one place, and we can just use str_value in Item directly. sql/item_timefunc.cc: Must defer a (possible) local SP variable to use max_length and str_value in Item_func_date_format::fix_length_and_dec(), and refer to str_value directly without the const_string() method (now removed); the cast didn't work in all cases anyway.
-rw-r--r--mysql-test/r/sp.result19
-rw-r--r--mysql-test/t/sp.test25
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_timefunc.cc13
4 files changed, 54 insertions, 4 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index a4c920f8e15..0029c79450b 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -4768,4 +4768,23 @@ Handler
Inner
drop procedure bug15011|
drop table t3|
+drop procedure if exists bug17476|
+create table t3 ( d date )|
+insert into t3 values
+( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ),
+( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )|
+create procedure bug17476(pDateFormat varchar(10))
+select date_format(t3.d, pDateFormat), count(*)
+from t3
+group by date_format(t3.d, pDateFormat)|
+call bug17476('%Y-%m')|
+date_format(t3.d, pDateFormat) count(*)
+2005-01 4
+2005-02 2
+call bug17476('%Y-%m')|
+date_format(t3.d, pDateFormat) count(*)
+2005-01 4
+2005-02 2
+drop table t3|
+drop procedure bug17476|
drop table t1,t2;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 243c1b413b7..12c1aebb265 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -5616,6 +5616,31 @@ drop table t3|
#
+# BUG#17476: Stored procedure not returning data when it is called first
+# time per connection
+#
+--disable_warnings
+drop procedure if exists bug17476|
+--enable_warnings
+
+create table t3 ( d date )|
+insert into t3 values
+ ( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ),
+ ( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )|
+
+create procedure bug17476(pDateFormat varchar(10))
+ select date_format(t3.d, pDateFormat), count(*)
+ from t3
+ group by date_format(t3.d, pDateFormat)|
+
+call bug17476('%Y-%m')|
+call bug17476('%Y-%m')|
+
+drop table t3|
+drop procedure bug17476|
+
+
+#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
diff --git a/sql/item.h b/sql/item.h
index a859b067632..2e3e0acc408 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1585,7 +1585,6 @@ public:
str_value.length(), collation.collation);
}
Item *safe_charset_converter(CHARSET_INFO *tocs);
- String *const_string() { return &str_value; }
inline void append(char *str, uint length) { str_value.append(str, length); }
void print(String *str);
// to prevent drop fixed flag (no need parent cleanup call)
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 17f25b49bcc..63a7f1f130b 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1605,9 +1605,15 @@ longlong Item_func_sec_to_time::val_int()
void Item_func_date_format::fix_length_and_dec()
{
+ /*
+ Must use this_item() in case it's a local SP variable
+ (for ->max_length and ->str_value)
+ */
+ Item *arg1= args[1]->this_item();
+
decimals=0;
collation.set(&my_charset_bin);
- if (args[1]->type() == STRING_ITEM)
+ if (arg1->type() == STRING_ITEM)
{ // Optimize the normal case
fixed_length=1;
@@ -1615,13 +1621,13 @@ void Item_func_date_format::fix_length_and_dec()
The result is a binary string (no reason to use collation->mbmaxlen
This is becasue make_date_time() only returns binary strings
*/
- max_length= format_length(((Item_string*) args[1])->const_string());
+ max_length= format_length(&arg1->str_value);
}
else
{
fixed_length=0;
/* The result is a binary string (no reason to use collation->mbmaxlen */
- max_length=min(args[1]->max_length,MAX_BLOB_WIDTH) * 10;
+ max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10;
set_if_smaller(max_length,MAX_BLOB_WIDTH);
}
maybe_null=1; // If wrong date
@@ -1631,6 +1637,7 @@ void Item_func_date_format::fix_length_and_dec()
bool Item_func_date_format::eq(const Item *item, bool binary_cmp) const
{
Item_func_date_format *item_func;
+
if (item->type() != FUNC_ITEM)
return 0;
if (func_name() != ((Item_func*) item)->func_name())