diff options
-rw-r--r-- | mysql-test/r/func_str.result | 6 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 6 | ||||
-rw-r--r-- | sql/item_func.cc | 12 |
3 files changed, 20 insertions, 4 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 5405dbf53d9..ea1efbc7c0a 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -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 diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 22028437111..a5536f7a0be 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -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); diff --git a/sql/item_func.cc b/sql/item_func.cc index 3c50e750b41..1300dc6faac 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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,8 +1509,8 @@ 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()) - return (longlong) (i); + if (!args[i]->null_value && val == args[i]->val_int()) + return (longlong) (i); } } else @@ -1514,8 +1518,8 @@ longlong Item_func_field::val_int() double val= args[0]->val(); for (uint i=1; i < arg_count ; i++) { - if (val == args[i]->val()) - return (longlong) (i); + if (!args[i]->null_value && val == args[i]->val()) + return (longlong) (i); } } return 0; |