Commit 7ac7bfc3 authored by jimw@mysql.com's avatar jimw@mysql.com

Fix handling of NULL fields in FIELD(). (Bug #10944)

parent e877e71b
...@@ -783,3 +783,9 @@ id aes_decrypt(str, 'bar') ...@@ -783,3 +783,9 @@ id aes_decrypt(str, 'bar')
1 foo 1 foo
2 NULL 2 NULL
DROP TABLE t1, t2; DROP TABLE t1, t2;
select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
field(0,NULL,1,0) field("",NULL,"bar","") field(0.0,NULL,1.0,0.0)
3 3 3
select field(NULL,1,2,NULL), field(NULL,1,2,0);
field(NULL,1,2,NULL) field(NULL,1,2,0)
0 0
...@@ -521,3 +521,9 @@ SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id ...@@ -521,3 +521,9 @@ SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id
DROP TABLE t1, t2; DROP TABLE t1, t2;
#
# Bug #10944: Mishandling of NULL arguments in FIELD()
#
select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
select field(NULL,1,2,NULL), field(NULL,1,2,0);
...@@ -1488,6 +1488,10 @@ void Item_func_locate::print(String *str) ...@@ -1488,6 +1488,10 @@ void Item_func_locate::print(String *str)
longlong Item_func_field::val_int() longlong Item_func_field::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (args[0]->null_value)
return 0;
if (cmp_type == STRING_RESULT) if (cmp_type == STRING_RESULT)
{ {
String *field; String *field;
...@@ -1505,8 +1509,8 @@ longlong Item_func_field::val_int() ...@@ -1505,8 +1509,8 @@ longlong Item_func_field::val_int()
longlong val= args[0]->val_int(); longlong val= args[0]->val_int();
for (uint i=1; i < arg_count ; i++) for (uint i=1; i < arg_count ; i++)
{ {
if (val == args[i]->val_int()) if (!args[i]->null_value && val == args[i]->val_int())
return (longlong) (i); return (longlong) (i);
} }
} }
else else
...@@ -1514,8 +1518,8 @@ longlong Item_func_field::val_int() ...@@ -1514,8 +1518,8 @@ longlong Item_func_field::val_int()
double val= args[0]->val(); double val= args[0]->val();
for (uint i=1; i < arg_count ; i++) for (uint i=1; i < arg_count ; i++)
{ {
if (val == args[i]->val()) if (!args[i]->null_value && val == args[i]->val())
return (longlong) (i); return (longlong) (i);
} }
} }
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