Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.1940 05/06/02 07:27:02 igor@stripped +7 -0
item_func.h:
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
The str_op virtual method was added into Item_func_numhybrid.
item_func.cc:
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
The str_op virtual method was added into Item_func_numhybrid.
item_cmpfunc.h, item_cmpfunc.cc:
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
Item_func_coalesce and Item_func_ifnull now
inherit from a modified Item_func_numhybrid.
case.test, case.result:
Added test cases for bug #9939.
BitKeeper/etc/logging_ok
1.319 05/06/02 07:27:01 igor@stripped +1 -0
Logging to logging@stripped accepted
sql/item_func.h
1.116 05/06/02 07:23:56 igor@stripped +6 -0
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
he str_op virtual method was added into Item_func_numhybrid.
sql/item_func.cc
1.203 05/06/02 07:22:02 igor@stripped +25 -0
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
The str_op virtual method was added into Item_func_numhybrid.
sql/item_cmpfunc.h
1.101 05/06/02 07:20:27 igor@stripped +13 -17
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
Item_func_coalesce and Item_func_ifnull now
inherit from a modified Item_func_numhybrid.
sql/item_cmpfunc.cc
1.149 05/06/02 07:16:47 igor@stripped +12 -12
Fixed bug #9939: a wrong conversion of arguments
for functions COALESCE and IFNULL.
Item_func_coalesce and Item_func_ifnull now
inherit from a modified Item_func_numhybrid.
mysql-test/t/case.test
1.16 05/06/02 07:15:37 igor@stripped +19 -0
Added test cases for bug #9939.
mysql-test/r/case.result
1.22 05/06/02 07:15:00 igor@stripped +17 -0
Added test cases for bug #9939.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: igor
# Host: igor-inspiron.creware.com
# Root: /home/igor/dev/mysql-5.0-0
--- 1.148/sql/item_cmpfunc.cc Tue May 31 03:06:09 2005
+++ 1.149/sql/item_cmpfunc.cc Thu Jun 2 07:16:47 2005
@@ -1114,8 +1114,8 @@
max_length= (max(args[0]->max_length - args[0]->decimals,
args[1]->max_length - args[1]->decimals) +
decimals);
- agg_result_type(&cached_result_type, args, 2);
- switch (cached_result_type) {
+ agg_result_type(&hybrid_type, args, 2);
+ switch (hybrid_type) {
case STRING_RESULT:
agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV);
break;
@@ -1153,7 +1153,7 @@
}
double
-Item_func_ifnull::val_real()
+Item_func_ifnull::real_op()
{
DBUG_ASSERT(fixed == 1);
double value= args[0]->val_real();
@@ -1169,7 +1169,7 @@
}
longlong
-Item_func_ifnull::val_int()
+Item_func_ifnull::int_op()
{
DBUG_ASSERT(fixed == 1);
longlong value=args[0]->val_int();
@@ -1185,7 +1185,7 @@
}
-my_decimal *Item_func_ifnull::val_decimal(my_decimal *decimal_value)
+my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
my_decimal *value= args[0]->val_decimal(decimal_value);
@@ -1202,7 +1202,7 @@
String *
-Item_func_ifnull::val_str(String *str)
+Item_func_ifnull::str_op(String *str)
{
DBUG_ASSERT(fixed == 1);
String *res =args[0]->val_str(str);
@@ -1676,7 +1676,7 @@
Coalesce - return first not NULL argument.
*/
-String *Item_func_coalesce::val_str(String *str)
+String *Item_func_coalesce::str_op(String *str)
{
DBUG_ASSERT(fixed == 1);
null_value=0;
@@ -1690,7 +1690,7 @@
return 0;
}
-longlong Item_func_coalesce::val_int()
+longlong Item_func_coalesce::int_op()
{
DBUG_ASSERT(fixed == 1);
null_value=0;
@@ -1704,7 +1704,7 @@
return 0;
}
-double Item_func_coalesce::val_real()
+double Item_func_coalesce::real_op()
{
DBUG_ASSERT(fixed == 1);
null_value=0;
@@ -1719,7 +1719,7 @@
}
-my_decimal *Item_func_coalesce::val_decimal(my_decimal *decimal_value)
+my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
null_value= 0;
@@ -1736,8 +1736,8 @@
void Item_func_coalesce::fix_length_and_dec()
{
- agg_result_type(&cached_result_type, args, arg_count);
- switch (cached_result_type) {
+ agg_result_type(&hybrid_type, args, arg_count);
+ switch (hybrid_type) {
case STRING_RESULT:
count_only_length();
decimals= NOT_FIXED_DEC;
--- 1.100/sql/item_cmpfunc.h Mon May 9 02:26:46 2005
+++ 1.101/sql/item_cmpfunc.h Thu Jun 2 07:20:27 2005
@@ -453,23 +453,19 @@
};
-class Item_func_coalesce :public Item_func
+class Item_func_coalesce :public Item_func_numhybrid
{
protected:
- enum Item_result cached_result_type;
- Item_func_coalesce(Item *a, Item *b)
- :Item_func(a, b), cached_result_type(INT_RESULT)
- {}
+ Item_func_coalesce(Item *a, Item *b) :Item_func_numhybrid(a, b) {}
public:
- Item_func_coalesce(List<Item> &list)
- :Item_func(list),cached_result_type(INT_RESULT)
- {}
- double val_real();
- longlong val_int();
- String *val_str(String *);
- my_decimal *val_decimal(my_decimal *);
+ Item_func_coalesce(List<Item> &list) :Item_func_numhybrid(list) {}
+ double real_op();
+ longlong int_op();
+ String *str_op(String *);
+ my_decimal *decimal_op(my_decimal *);
void fix_length_and_dec();
- enum Item_result result_type () const { return cached_result_type; }
+ void find_num_type() {}
+ enum Item_result result_type () const { return hybrid_type; }
const char *func_name() const { return "coalesce"; }
table_map not_null_tables() const { return 0; }
};
@@ -482,10 +478,10 @@
bool field_type_defined;
public:
Item_func_ifnull(Item *a, Item *b) :Item_func_coalesce(a,b) {}
- double val_real();
- longlong val_int();
- String *val_str(String *str);
- my_decimal *val_decimal(my_decimal *);
+ double real_op();
+ longlong int_op();
+ String *str_op(String *str);
+ my_decimal *decimal_op(my_decimal *);
enum_field_types field_type() const;
void fix_length_and_dec();
const char *func_name() const { return "ifnull"; }
--- 1.202/sql/item_func.cc Tue May 31 03:06:09 2005
+++ 1.203/sql/item_func.cc Thu Jun 2 07:22:02 2005
@@ -815,6 +815,8 @@
str->set(nr,decimals,&my_charset_bin);
break;
}
+ case STRING_RESULT:
+ return str_op(&str_value);
default:
DBUG_ASSERT(0);
}
@@ -839,6 +841,14 @@
return (double)int_op();
case REAL_RESULT:
return real_op();
+ case STRING_RESULT:
+ {
+ char *end_not_used;
+ int err_not_used;
+ String *res= str_op(&str_value);
+ return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
+ &end_not_used, &err_not_used) : 0.0);
+ }
default:
DBUG_ASSERT(0);
}
@@ -863,6 +873,15 @@
return int_op();
case REAL_RESULT:
return (longlong)real_op();
+ case STRING_RESULT:
+ {
+ char *end_not_used;
+ int err_not_used;
+ String *res= str_op(&str_value);
+ CHARSET_INFO *cs= str_value.charset();
+ return (res ? (*(cs->cset->strtoll10))(cs, res->ptr(), &end_not_used,
+ &err_not_used) : 0);
+ }
default:
DBUG_ASSERT(0);
}
@@ -891,6 +910,12 @@
break;
}
case STRING_RESULT:
+ {
+ String *res= str_op(&str_value);
+ str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
+ res->length(), res->charset(), decimal_value);
+ break;
+ }
case ROW_RESULT:
default:
DBUG_ASSERT(0);
--- 1.115/sql/item_func.h Tue May 10 03:33:41 2005
+++ 1.116/sql/item_func.h Thu Jun 2 07:23:56 2005
@@ -194,6 +194,9 @@
Item_func_numhybrid(Item *a,Item *b)
:Item_func(a,b),hybrid_type(REAL_RESULT)
{}
+ Item_func_numhybrid(List<Item> &list)
+ :Item_func(list),hybrid_type(REAL_RESULT)
+ {}
enum Item_result result_type () const { return hybrid_type; }
void fix_length_and_dec();
@@ -208,6 +211,7 @@
virtual longlong int_op()= 0;
virtual double real_op()= 0;
virtual my_decimal *decimal_op(my_decimal *)= 0;
+ virtual String *str_op(String *)= 0;
bool is_null() { (void) val_real(); return null_value; }
};
@@ -220,6 +224,7 @@
void fix_num_length_and_dec();
void find_num_type();
+ String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
};
@@ -231,6 +236,7 @@
virtual void result_precision()= 0;
void print(String *str) { print_op(str); }
void find_num_type();
+ String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
};
--- 1.318/BitKeeper/etc/logging_ok Tue May 24 17:15:08 2005
+++ 1.319/BitKeeper/etc/logging_ok Thu Jun 2 07:27:01 2005
@@ -87,6 +87,7 @@
hf@genie.(none)
holyfoot@stripped
igor@stripped
+igor@stripped
igor@stripped
igor@stripped
ingo@stripped
--- 1.21/mysql-test/r/case.result Thu May 5 13:01:34 2005
+++ 1.22/mysql-test/r/case.result Thu Jun 2 07:15:00 2005
@@ -160,3 +160,20 @@
`COALESCE('a' COLLATE latin1_bin,'b')` varchar(1) character set latin1 collate latin1_bin NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
+CREATE TABLE t1 (EMPNUM INT);
+INSERT INTO t1 VALUES (0), (2);
+CREATE TABLE t2 (EMPNUM DECIMAL (4, 2));
+INSERT INTO t2 VALUES (0.0), (9.0);
+SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
+t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
+FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
+CEMPNUM EMPMUM1 EMPNUM2
+0.00 0 0.00
+2.00 2 NULL
+SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
+t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
+FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
+CEMPNUM EMPMUM1 EMPNUM2
+0.00 0 0.00
+2.00 2 NULL
+DROP TABLE t1,t2;
--- 1.15/mysql-test/t/case.test Tue Feb 8 14:49:33 2005
+++ 1.16/mysql-test/t/case.test Thu Jun 2 07:15:37 2005
@@ -110,3 +110,22 @@
COALESCE('a' COLLATE latin1_bin,'b');
SHOW CREATE TABLE t1;
DROP TABLE t1;
+
+#
+# Tests for bug #9939: conversion of the arguments for COALESCE and IFNULL
+#
+
+CREATE TABLE t1 (EMPNUM INT);
+INSERT INTO t1 VALUES (0), (2);
+CREATE TABLE t2 (EMPNUM DECIMAL (4, 2));
+INSERT INTO t2 VALUES (0.0), (9.0);
+
+SELECT COALESCE(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
+ t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
+ FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
+
+SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CEMPNUM,
+ t1.EMPNUM AS EMPMUM1, t2.EMPNUM AS EMPNUM2
+ FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;
+
+DROP TABLE t1,t2;
| Thread |
|---|
| • bk commit into 5.0 tree (igor:1.1940) BUG#9939 | igor | 2 Jun |