diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 87615b4537e..7909fabc971 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -40,3 +40,6 @@ cast("1:2:3" as TIME) = "1:02:03" select cast(NULL as DATE); cast(NULL as DATE) NULL +select cast(NULL as BINARY); +cast(NULL as BINARY) +NULL diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 402adf276c5..8703a6b739d 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -21,3 +21,4 @@ select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"; select cast("1:2:3" as TIME) = "1:02:03"; select cast(NULL as DATE); +select cast(NULL as BINARY); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 4d2aaf5a0f2..09f0aeefb09 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -769,7 +769,8 @@ Item_func_if::val_str(String *str) { Item *arg= args[0]->val_int() ? args[1] : args[2]; String *res=arg->val_str(str); - res->set_charset(charset()); + if (res) + res->set_charset(charset()); null_value=arg->null_value; return res; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 07b7eb2d165..e403b970fe1 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -512,7 +512,8 @@ public: { String *tmp=args[0]->val_str(a); null_value=args[0]->null_value; - tmp->set_charset(&my_charset_bin); + if (tmp) + tmp->set_charset(&my_charset_bin); return tmp; } void fix_length_and_dec()