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/dayofmonth.h>
00025
00026 namespace drizzled
00027 {
00028
00029 int64_t Item_func_dayofmonth::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 DateTime temporal;
00042 Item_result arg0_result_type= args[0]->result_type();
00043
00044 switch (arg0_result_type)
00045 {
00046 case DECIMAL_RESULT:
00047
00048
00049
00050
00051
00052
00053
00054
00055 case STRING_RESULT:
00056 {
00057 char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
00058 String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
00059 String *res= args[0]->val_str(&tmp);
00060
00061 if (res && (res != &tmp))
00062 {
00063 tmp.copy(*res);
00064 }
00065
00066 if (! temporal.from_string(tmp.c_ptr(), tmp.length()))
00067 {
00068
00069
00070
00071
00072 my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
00073 return 0;
00074 }
00075 }
00076 break;
00077 case INT_RESULT:
00078 if (temporal.from_int64_t(args[0]->val_int()))
00079 break;
00080
00081 default:
00082 {
00083
00084
00085
00086
00087 null_value= true;
00088 char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
00089 String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
00090 String *res;
00091
00092 res= args[0]->val_str(&tmp);
00093
00094 if (res && (res != &tmp))
00095 {
00096 tmp.copy(*res);
00097 }
00098
00099 my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
00100 return 0;
00101 }
00102 }
00103 return (int64_t) temporal.days();
00104 }
00105
00106 }