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