@@ -871,7 +871,7 @@ void Item_func_num1::fix_length_and_dec()
871871String *Item_func_hybrid_field_type::val_str (String *str)
872872{
873873 DBUG_ASSERT (fixed == 1 );
874- switch (Item_func_hybrid_field_type::result_type ()) {
874+ switch (Item_func_hybrid_field_type::cmp_type ()) {
875875 case DECIMAL_RESULT:
876876 {
877877 my_decimal decimal_value, *val;
@@ -898,24 +898,23 @@ String *Item_func_hybrid_field_type::val_str(String *str)
898898 str->set_real (nr, decimals, collation.collation );
899899 break ;
900900 }
901- case STRING_RESULT:
902- if (is_temporal_type (field_type ()))
901+ case TIME_RESULT:
902+ {
903+ MYSQL_TIME ltime;
904+ if (date_op (<ime,
905+ field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ) ||
906+ str->alloc (MAX_DATE_STRING_REP_LENGTH))
903907 {
904- MYSQL_TIME ltime;
905- if (date_op (<ime,
906- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ) ||
907- str->alloc (MAX_DATE_STRING_REP_LENGTH))
908- {
909- null_value= 1 ;
910- return (String *) 0 ;
911- }
912- ltime.time_type = mysql_type_to_time_type (field_type ());
913- str->length (my_TIME_to_str (<ime, const_cast <char *>(str->ptr ()), decimals));
914- str->set_charset (&my_charset_bin);
915- return str;
908+ null_value= 1 ;
909+ return (String *) 0 ;
916910 }
911+ ltime.time_type = mysql_type_to_time_type (field_type ());
912+ str->length (my_TIME_to_str (<ime, const_cast <char *>(str->ptr ()), decimals));
913+ str->set_charset (&my_charset_bin);
914+ return str;
915+ }
916+ case STRING_RESULT:
917917 return str_op (&str_value);
918- case TIME_RESULT:
919918 case ROW_RESULT:
920919 DBUG_ASSERT (0 );
921920 }
@@ -926,7 +925,7 @@ String *Item_func_hybrid_field_type::val_str(String *str)
926925double Item_func_hybrid_field_type::val_real ()
927926{
928927 DBUG_ASSERT (fixed == 1 );
929- switch (Item_func_hybrid_field_type::result_type ()) {
928+ switch (Item_func_hybrid_field_type::cmp_type ()) {
930929 case DECIMAL_RESULT:
931930 {
932931 my_decimal decimal_value, *val;
@@ -943,24 +942,23 @@ double Item_func_hybrid_field_type::val_real()
943942 }
944943 case REAL_RESULT:
945944 return real_op ();
946- case STRING_RESULT :
945+ case TIME_RESULT :
947946 {
948- if (is_temporal_type (field_type ()))
947+ MYSQL_TIME ltime;
948+ if (date_op (<ime,
949+ field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
949950 {
950- MYSQL_TIME ltime;
951- if (date_op (<ime,
952- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
953- {
954- null_value= 1 ;
955- return 0 ;
956- }
957- ltime.time_type = mysql_type_to_time_type (field_type ());
958- return TIME_to_double (<ime);
951+ null_value= 1 ;
952+ return 0 ;
959953 }
954+ ltime.time_type = mysql_type_to_time_type (field_type ());
955+ return TIME_to_double (<ime);
956+ }
957+ case STRING_RESULT:
958+ {
960959 String *res= str_op (&str_value);
961960 return res ? double_from_string_with_check (res) : 0.0 ;
962961 }
963- case TIME_RESULT:
964962 case ROW_RESULT:
965963 DBUG_ASSERT (0 );
966964 }
@@ -971,7 +969,7 @@ double Item_func_hybrid_field_type::val_real()
971969longlong Item_func_hybrid_field_type::val_int ()
972970{
973971 DBUG_ASSERT (fixed == 1 );
974- switch (Item_func_hybrid_field_type::result_type ()) {
972+ switch (Item_func_hybrid_field_type::cmp_type ()) {
975973 case DECIMAL_RESULT:
976974 {
977975 my_decimal decimal_value, *val;
@@ -985,24 +983,23 @@ longlong Item_func_hybrid_field_type::val_int()
985983 return int_op ();
986984 case REAL_RESULT:
987985 return (longlong) rint (real_op ());
988- case STRING_RESULT :
986+ case TIME_RESULT :
989987 {
990- if (is_temporal_type (field_type ()))
988+ MYSQL_TIME ltime;
989+ if (date_op (<ime,
990+ field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
991991 {
992- MYSQL_TIME ltime;
993- if (date_op (<ime,
994- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
995- {
996- null_value= 1 ;
997- return 0 ;
998- }
999- ltime.time_type = mysql_type_to_time_type (field_type ());
1000- return TIME_to_ulonglong (<ime);
992+ null_value= 1 ;
993+ return 0 ;
1001994 }
995+ ltime.time_type = mysql_type_to_time_type (field_type ());
996+ return TIME_to_ulonglong (<ime);
997+ }
998+ case STRING_RESULT:
999+ {
10021000 String *res= str_op (&str_value);
10031001 return res ? longlong_from_string_with_check (res) : 0 ;
10041002 }
1005- case TIME_RESULT:
10061003 case ROW_RESULT:
10071004 DBUG_ASSERT (0 );
10081005 }
@@ -1014,7 +1011,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
10141011{
10151012 my_decimal *val= decimal_value;
10161013 DBUG_ASSERT (fixed == 1 );
1017- switch (Item_func_hybrid_field_type::result_type ()) {
1014+ switch (Item_func_hybrid_field_type::cmp_type ()) {
10181015 case DECIMAL_RESULT:
10191016 val= decimal_op (decimal_value);
10201017 break ;
@@ -1030,26 +1027,25 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
10301027 double2my_decimal (E_DEC_FATAL_ERROR, result, decimal_value);
10311028 break ;
10321029 }
1033- case STRING_RESULT :
1030+ case TIME_RESULT :
10341031 {
1035- if (is_temporal_type (field_type ()))
1032+ MYSQL_TIME ltime;
1033+ if (date_op (<ime,
1034+ field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
10361035 {
1037- MYSQL_TIME ltime;
1038- if (date_op (<ime,
1039- field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
1040- {
1041- my_decimal_set_zero (decimal_value);
1042- null_value= 1 ;
1043- return 0 ;
1044- }
1045- ltime.time_type = mysql_type_to_time_type (field_type ());
1046- return date2my_decimal (<ime, decimal_value);
1036+ my_decimal_set_zero (decimal_value);
1037+ null_value= 1 ;
1038+ return 0 ;
10471039 }
1040+ ltime.time_type = mysql_type_to_time_type (field_type ());
1041+ return date2my_decimal (<ime, decimal_value);
1042+ }
1043+ case STRING_RESULT:
1044+ {
10481045 String *res= str_op (&str_value);
10491046 return res ? decimal_from_string_with_check (decimal_value, res) : 0 ;
10501047 }
10511048 case ROW_RESULT:
1052- case TIME_RESULT:
10531049 DBUG_ASSERT (0 );
10541050 }
10551051 return val;
@@ -1060,7 +1056,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
10601056 ulonglong fuzzydate)
10611057{
10621058 DBUG_ASSERT (fixed == 1 );
1063- switch (Item_func_hybrid_field_type::result_type ()) {
1059+ switch (Item_func_hybrid_field_type::cmp_type ()) {
10641060 case DECIMAL_RESULT:
10651061 {
10661062 my_decimal value, *res;
@@ -1088,23 +1084,21 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
10881084 goto err;
10891085 break ;
10901086 }
1087+ case TIME_RESULT:
1088+ return date_op (ltime,
1089+ fuzzydate |
1090+ (field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ));
10911091 case STRING_RESULT:
10921092 {
1093- if (is_temporal_type (field_type ()))
1094- return date_op (ltime,
1095- fuzzydate |
1096- (field_type () == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ));
10971093 char buff[40 ];
10981094 String tmp (buff,sizeof (buff), &my_charset_bin),*res;
10991095 if (!(res= str_op (&tmp)) ||
11001096 str_to_datetime_with_warn (res->charset (), res->ptr (), res->length (),
11011097 ltime, fuzzydate))
11021098 goto err;
11031099 break ;
1104- break ;
11051100 }
11061101 case ROW_RESULT:
1107- case TIME_RESULT:
11081102 DBUG_ASSERT (0 );
11091103 }
11101104
0 commit comments