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

This commit is contained in:
jimw@mysql.com 2005-06-01 09:48:25 -07:00
parent e877e71b17
commit 7ac7bfc3c8
3 changed files with 20 additions and 4 deletions

View file

@ -783,3 +783,9 @@ id aes_decrypt(str, 'bar')
1 foo
2 NULL
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

View file

@ -521,3 +521,9 @@ SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id
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);

View file

@ -1488,6 +1488,10 @@ void Item_func_locate::print(String *str)
longlong Item_func_field::val_int()
{
DBUG_ASSERT(fixed == 1);
if (args[0]->null_value)
return 0;
if (cmp_type == STRING_RESULT)
{
String *field;
@ -1505,7 +1509,7 @@ longlong Item_func_field::val_int()
longlong val= args[0]->val_int();
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);
}
}
@ -1514,7 +1518,7 @@ longlong Item_func_field::val_int()
double val= args[0]->val();
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);
}
}