00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/temporal.h>
00023 #include <drizzled/error.h>
00024 #include <drizzled/function/time/hour.h>
00025
00026 namespace drizzled
00027 {
00028
00029 int64_t Item_func_hour::val_int()
00030 {
00031 assert(fixed);
00032
00033 if (args[0]->is_null())
00034 {
00035
00036 null_value= true;
00037 return 0;
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 Time temporal_time;
00056
00057 char time_buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
00058 String tmp_time(time_buff,sizeof(time_buff), &my_charset_utf8_bin);
00059 String *time_res= args[0]->val_str(&tmp_time);
00060
00061 if (time_res && (time_res != &tmp_time))
00062 {
00063 tmp_time.copy(*time_res);
00064 }
00065
00066 if (! temporal_time.from_string(tmp_time.c_ptr(), tmp_time.length()))
00067 {
00068
00069
00070
00071
00072
00073 DateTime temporal_datetime;
00074 Item_result arg0_result_type= args[0]->result_type();
00075
00076 switch (arg0_result_type)
00077 {
00078 case DECIMAL_RESULT:
00079
00080
00081
00082
00083
00084
00085
00086
00087 case STRING_RESULT:
00088 {
00089 char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
00090 String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
00091 String *res= args[0]->val_str(&tmp);
00092
00093 if (res && (res != &tmp))
00094 {
00095 tmp.copy(*res);
00096 }
00097
00098 if (! temporal_datetime.from_string(tmp.c_ptr(), tmp.length()))
00099 {
00100
00101
00102
00103
00104 my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
00105 return 0;
00106 }
00107 }
00108 break;
00109 case INT_RESULT:
00110 if (temporal_datetime.from_int64_t(args[0]->val_int()))
00111 break;
00112
00113 default:
00114 {
00115
00116
00117
00118
00119 null_value= true;
00120 char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
00121 String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
00122 String *res;
00123
00124 res= args[0]->val_str(&tmp);
00125
00126 if (res && (res != &tmp))
00127 {
00128 tmp.copy(*res);
00129 }
00130
00131 my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
00132 return 0;
00133 }
00134 }
00135 return (int64_t) temporal_datetime.hours();
00136 }
00137 return (int64_t) temporal_time.hours();
00138 }
00139
00140 }