@@ -887,7 +887,7 @@ String *Item_func_hybrid_result_type::val_str(String *str)
887887 case DECIMAL_RESULT:
888888 {
889889 my_decimal decimal_value, *val;
890- if (!(val= decimal_op (&decimal_value)))
890+ if (!(val= decimal_op_with_null_check (&decimal_value)))
891891 return 0 ; // null is set
892892 my_decimal_round (E_DEC_FATAL_ERROR, val, decimals, FALSE , val);
893893 str->set_charset (collation.collation );
@@ -914,24 +914,22 @@ String *Item_func_hybrid_result_type::val_str(String *str)
914914 if (is_temporal_type (field_type ()))
915915 {
916916 MYSQL_TIME ltime;
917- if (date_op (<ime,
918- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ) ||
919- str->alloc (MAX_DATE_STRING_REP_LENGTH))
920- {
921- null_value= 1 ;
917+ if (date_op_with_null_check (<ime) ||
918+ (null_value= str->alloc (MAX_DATE_STRING_REP_LENGTH)))
922919 return (String *) 0 ;
923- }
924920 ltime.time_type = mysql_type_to_time_type (field_type ());
925921 str->length (my_TIME_to_str (<ime, const_cast <char *>(str->ptr ()), decimals));
926922 str->set_charset (&my_charset_bin);
923+ DBUG_ASSERT (!null_value);
927924 return str;
928925 }
929- return str_op (&str_value);
926+ return str_op_with_null_check (&str_value);
930927 case TIME_RESULT:
931928 case ROW_RESULT:
932929 case IMPOSSIBLE_RESULT:
933930 DBUG_ASSERT (0 );
934931 }
932+ DBUG_ASSERT (!null_value || (str == NULL ));
935933 return str;
936934}
937935
@@ -944,7 +942,7 @@ double Item_func_hybrid_result_type::val_real()
944942 {
945943 my_decimal decimal_value, *val;
946944 double result;
947- if (!(val= decimal_op (&decimal_value)))
945+ if (!(val= decimal_op_with_null_check (&decimal_value)))
948946 return 0.0 ; // null is set
949947 my_decimal2double (E_DEC_FATAL_ERROR, val, &result);
950948 return result;
@@ -961,18 +959,14 @@ double Item_func_hybrid_result_type::val_real()
961959 if (is_temporal_type (field_type ()))
962960 {
963961 MYSQL_TIME ltime;
964- if (date_op (<ime,
965- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
966- {
967- null_value= 1 ;
962+ if (date_op_with_null_check (<ime))
968963 return 0 ;
969- }
970964 ltime.time_type = mysql_type_to_time_type (field_type ());
971965 return TIME_to_double (<ime);
972966 }
973967 char *end_not_used;
974968 int err_not_used;
975- String *res= str_op (&str_value);
969+ String *res= str_op_with_null_check (&str_value);
976970 return (res ? my_strntod (res->charset (), (char *) res->ptr (), res->length (),
977971 &end_not_used, &err_not_used) : 0.0 );
978972 }
@@ -992,7 +986,7 @@ longlong Item_func_hybrid_result_type::val_int()
992986 case DECIMAL_RESULT:
993987 {
994988 my_decimal decimal_value, *val;
995- if (!(val= decimal_op (&decimal_value)))
989+ if (!(val= decimal_op_with_null_check (&decimal_value)))
996990 return 0 ; // null is set
997991 longlong result;
998992 my_decimal2int (E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
@@ -1007,18 +1001,14 @@ longlong Item_func_hybrid_result_type::val_int()
10071001 if (is_temporal_type (field_type ()))
10081002 {
10091003 MYSQL_TIME ltime;
1010- if (date_op (<ime,
1011- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
1012- {
1013- null_value= 1 ;
1004+ if (date_op_with_null_check (<ime))
10141005 return 0 ;
1015- }
10161006 ltime.time_type = mysql_type_to_time_type (field_type ());
10171007 return TIME_to_ulonglong (<ime);
10181008 }
10191009 int err_not_used;
10201010 String *res;
1021- if (!(res= str_op (&str_value)))
1011+ if (!(res= str_op_with_null_check (&str_value)))
10221012 return 0 ;
10231013
10241014 char *end= (char *) res->ptr () + res->length ();
@@ -1040,17 +1030,21 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
10401030 DBUG_ASSERT (fixed == 1 );
10411031 switch (cached_result_type) {
10421032 case DECIMAL_RESULT:
1043- val= decimal_op (decimal_value);
1033+ val= decimal_op_with_null_check (decimal_value);
10441034 break ;
10451035 case INT_RESULT:
10461036 {
10471037 longlong result= int_op ();
1038+ if (null_value)
1039+ return NULL ;
10481040 int2my_decimal (E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
10491041 break ;
10501042 }
10511043 case REAL_RESULT:
10521044 {
10531045 double result= (double )real_op ();
1046+ if (null_value)
1047+ return NULL ;
10541048 double2my_decimal (E_DEC_FATAL_ERROR, result, decimal_value);
10551049 break ;
10561050 }
@@ -1059,19 +1053,20 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
10591053 if (is_temporal_type (field_type ()))
10601054 {
10611055 MYSQL_TIME ltime;
1062- if (date_op (<ime,
1063- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
1056+ if (date_op_with_null_check (<ime))
10641057 {
10651058 my_decimal_set_zero (decimal_value);
1066- null_value= 1 ;
10671059 return 0 ;
10681060 }
10691061 ltime.time_type = mysql_type_to_time_type (field_type ());
10701062 return date2my_decimal (<ime, decimal_value);
10711063 }
10721064 String *res;
1073- if (!(res= str_op (&str_value)))
1065+ if (!(res= str_op_with_null_check (&str_value)))
1066+ {
1067+ null_value= 1 ;
10741068 return NULL ;
1069+ }
10751070
10761071 str2my_decimal (E_DEC_FATAL_ERROR, (char *) res->ptr (),
10771072 res->length (), res->charset (), decimal_value);
@@ -1094,7 +1089,7 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
10941089 case DECIMAL_RESULT:
10951090 {
10961091 my_decimal value, *res;
1097- if (!(res= decimal_op (&value)) ||
1092+ if (!(res= decimal_op_with_null_check (&value)) ||
10981093 decimal_to_datetime_with_warn (res, ltime, fuzzydate,
10991094 field_name_or_null ()))
11001095 goto err;
@@ -1124,7 +1119,7 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
11241119 return date_op (ltime, fuzzydate);
11251120 char buff[40 ];
11261121 String tmp (buff,sizeof (buff), &my_charset_bin),*res;
1127- if (!(res= str_op (&tmp)) ||
1122+ if (!(res= str_op_with_null_check (&tmp)) ||
11281123 str_to_datetime_with_warn (res->charset (), res->ptr (), res->length (),
11291124 ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
11301125 goto err;
0 commit comments