@@ -887,7 +887,7 @@ String *Item_func_hybrid_result_type::val_str(String *str)
887
887
case DECIMAL_RESULT:
888
888
{
889
889
my_decimal decimal_value, *val;
890
- if (!(val= decimal_op (&decimal_value)))
890
+ if (!(val= decimal_op_with_null_check (&decimal_value)))
891
891
return 0 ; // null is set
892
892
my_decimal_round (E_DEC_FATAL_ERROR, val, decimals, FALSE , val);
893
893
str->set_charset (collation.collation );
@@ -914,24 +914,22 @@ String *Item_func_hybrid_result_type::val_str(String *str)
914
914
if (is_temporal_type (field_type ()))
915
915
{
916
916
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)))
922
919
return (String *) 0 ;
923
- }
924
920
ltime.time_type = mysql_type_to_time_type (field_type ());
925
921
str->length (my_TIME_to_str (<ime, const_cast <char *>(str->ptr ()), decimals));
926
922
str->set_charset (&my_charset_bin);
923
+ DBUG_ASSERT (!null_value);
927
924
return str;
928
925
}
929
- return str_op (&str_value);
926
+ return str_op_with_null_check (&str_value);
930
927
case TIME_RESULT:
931
928
case ROW_RESULT:
932
929
case IMPOSSIBLE_RESULT:
933
930
DBUG_ASSERT (0 );
934
931
}
932
+ DBUG_ASSERT (!null_value || (str == NULL ));
935
933
return str;
936
934
}
937
935
@@ -944,7 +942,7 @@ double Item_func_hybrid_result_type::val_real()
944
942
{
945
943
my_decimal decimal_value, *val;
946
944
double result;
947
- if (!(val= decimal_op (&decimal_value)))
945
+ if (!(val= decimal_op_with_null_check (&decimal_value)))
948
946
return 0.0 ; // null is set
949
947
my_decimal2double (E_DEC_FATAL_ERROR, val, &result);
950
948
return result;
@@ -961,18 +959,14 @@ double Item_func_hybrid_result_type::val_real()
961
959
if (is_temporal_type (field_type ()))
962
960
{
963
961
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))
968
963
return 0 ;
969
- }
970
964
ltime.time_type = mysql_type_to_time_type (field_type ());
971
965
return TIME_to_double (<ime);
972
966
}
973
967
char *end_not_used;
974
968
int err_not_used;
975
- String *res= str_op (&str_value);
969
+ String *res= str_op_with_null_check (&str_value);
976
970
return (res ? my_strntod (res->charset (), (char *) res->ptr (), res->length (),
977
971
&end_not_used, &err_not_used) : 0.0 );
978
972
}
@@ -992,7 +986,7 @@ longlong Item_func_hybrid_result_type::val_int()
992
986
case DECIMAL_RESULT:
993
987
{
994
988
my_decimal decimal_value, *val;
995
- if (!(val= decimal_op (&decimal_value)))
989
+ if (!(val= decimal_op_with_null_check (&decimal_value)))
996
990
return 0 ; // null is set
997
991
longlong result;
998
992
my_decimal2int (E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
@@ -1007,18 +1001,14 @@ longlong Item_func_hybrid_result_type::val_int()
1007
1001
if (is_temporal_type (field_type ()))
1008
1002
{
1009
1003
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))
1014
1005
return 0 ;
1015
- }
1016
1006
ltime.time_type = mysql_type_to_time_type (field_type ());
1017
1007
return TIME_to_ulonglong (<ime);
1018
1008
}
1019
1009
int err_not_used;
1020
1010
String *res;
1021
- if (!(res= str_op (&str_value)))
1011
+ if (!(res= str_op_with_null_check (&str_value)))
1022
1012
return 0 ;
1023
1013
1024
1014
char *end= (char *) res->ptr () + res->length ();
@@ -1040,17 +1030,21 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
1040
1030
DBUG_ASSERT (fixed == 1 );
1041
1031
switch (cached_result_type) {
1042
1032
case DECIMAL_RESULT:
1043
- val= decimal_op (decimal_value);
1033
+ val= decimal_op_with_null_check (decimal_value);
1044
1034
break ;
1045
1035
case INT_RESULT:
1046
1036
{
1047
1037
longlong result= int_op ();
1038
+ if (null_value)
1039
+ return NULL ;
1048
1040
int2my_decimal (E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
1049
1041
break ;
1050
1042
}
1051
1043
case REAL_RESULT:
1052
1044
{
1053
1045
double result= (double )real_op ();
1046
+ if (null_value)
1047
+ return NULL ;
1054
1048
double2my_decimal (E_DEC_FATAL_ERROR, result, decimal_value);
1055
1049
break ;
1056
1050
}
@@ -1059,19 +1053,20 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
1059
1053
if (is_temporal_type (field_type ()))
1060
1054
{
1061
1055
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))
1064
1057
{
1065
1058
my_decimal_set_zero (decimal_value);
1066
- null_value= 1 ;
1067
1059
return 0 ;
1068
1060
}
1069
1061
ltime.time_type = mysql_type_to_time_type (field_type ());
1070
1062
return date2my_decimal (<ime, decimal_value);
1071
1063
}
1072
1064
String *res;
1073
- if (!(res= str_op (&str_value)))
1065
+ if (!(res= str_op_with_null_check (&str_value)))
1066
+ {
1067
+ null_value= 1 ;
1074
1068
return NULL ;
1069
+ }
1075
1070
1076
1071
str2my_decimal (E_DEC_FATAL_ERROR, (char *) res->ptr (),
1077
1072
res->length (), res->charset (), decimal_value);
@@ -1094,7 +1089,7 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
1094
1089
case DECIMAL_RESULT:
1095
1090
{
1096
1091
my_decimal value, *res;
1097
- if (!(res= decimal_op (&value)) ||
1092
+ if (!(res= decimal_op_with_null_check (&value)) ||
1098
1093
decimal_to_datetime_with_warn (res, ltime, fuzzydate,
1099
1094
field_name_or_null ()))
1100
1095
goto err;
@@ -1124,7 +1119,7 @@ bool Item_func_hybrid_result_type::get_date(MYSQL_TIME *ltime,
1124
1119
return date_op (ltime, fuzzydate);
1125
1120
char buff[40 ];
1126
1121
String tmp (buff,sizeof (buff), &my_charset_bin),*res;
1127
- if (!(res= str_op (&tmp)) ||
1122
+ if (!(res= str_op_with_null_check (&tmp)) ||
1128
1123
str_to_datetime_with_warn (res->charset (), res->ptr (), res->length (),
1129
1124
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
1130
1125
goto err;
0 commit comments