Fix for bug #2629 NULLIF() doesn't behave as described in manual

parent 2bf78563
...@@ -40,6 +40,12 @@ a ...@@ -40,6 +40,12 @@ a
aa aa
aaa aaa
drop table t1; drop table t1;
select NULLIF(NULL,NULL), NULLIF(NULL,1), NULLIF(NULL,1.0), NULLIF(NULL,"test");
NULLIF(NULL,NULL) NULLIF(NULL,1) NULLIF(NULL,1.0) NULLIF(NULL,"test")
NULL NULL NULL NULL
select NULLIF(1,NULL), NULLIF(1.0, NULL), NULLIF("test", NULL);
NULLIF(1,NULL) NULLIF(1.0, NULL) NULLIF("test", NULL)
1 1.0 test
create table t1 (num double(12,2)); create table t1 (num double(12,2));
insert into t1 values (144.54); insert into t1 values (144.54);
select sum(if(num is null,0.00,num)) from t1; select sum(if(num is null,0.00,num)) from t1;
......
...@@ -20,6 +20,12 @@ select if(u=1,binary st,st) s from t1 order by s; ...@@ -20,6 +20,12 @@ select if(u=1,binary st,st) s from t1 order by s;
select if(u=1,st,binary st) s from t1 where st like "%a%" order by s; select if(u=1,st,binary st) s from t1 where st like "%a%" order by s;
drop table t1; drop table t1;
#
# Bug 2629
#
select NULLIF(NULL,NULL), NULLIF(NULL,1), NULLIF(NULL,1.0), NULLIF(NULL,"test");
select NULLIF(1,NULL), NULLIF(1.0, NULL), NULLIF("test", NULL);
# #
# Problem with IF() # Problem with IF()
# #
......
...@@ -616,7 +616,7 @@ double ...@@ -616,7 +616,7 @@ double
Item_func_nullif::val() Item_func_nullif::val()
{ {
double value; double value;
if (!(this->*cmp_func)() || null_value) if (!(this->*cmp_func)())
{ {
null_value=1; null_value=1;
return 0.0; return 0.0;
...@@ -630,7 +630,7 @@ longlong ...@@ -630,7 +630,7 @@ longlong
Item_func_nullif::val_int() Item_func_nullif::val_int()
{ {
longlong value; longlong value;
if (!(this->*cmp_func)() || null_value) if (!(this->*cmp_func)())
{ {
null_value=1; null_value=1;
return 0; return 0;
...@@ -644,7 +644,7 @@ String * ...@@ -644,7 +644,7 @@ String *
Item_func_nullif::val_str(String *str) Item_func_nullif::val_str(String *str)
{ {
String *res; String *res;
if (!(this->*cmp_func)() || null_value) if (!(this->*cmp_func)())
{ {
null_value=1; null_value=1;
return 0; return 0;
......
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