24 #include <drizzled/function/time/date_add_interval.h>
25 #include <drizzled/temporal_interval.h>
26 #include <drizzled/time_functions.h>
35 const char *interval_names[]=
37 "year",
"quarter",
"month",
"week",
"day",
38 "hour",
"minute",
"second",
"microsecond",
39 "year_month",
"day_hour",
"day_minute",
40 "day_second",
"hour_minute",
"hour_second",
41 "minute_second",
"day_microsecond",
42 "hour_microsecond",
"minute_microsecond",
47 void Item_date_add_interval::fix_length_and_dec()
49 enum_field_types arg0_field_type;
51 collation.set(&my_charset_bin);
54 value.alloc(max_length);
67 cached_field_type= DRIZZLE_TYPE_VARCHAR;
68 arg0_field_type= args[0]->field_type();
69 if (arg0_field_type == DRIZZLE_TYPE_DATETIME or arg0_field_type == DRIZZLE_TYPE_TIMESTAMP or arg0_field_type == DRIZZLE_TYPE_MICROTIME)
71 cached_field_type= DRIZZLE_TYPE_DATETIME;
73 else if (arg0_field_type == DRIZZLE_TYPE_DATE)
75 if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
77 cached_field_type= arg0_field_type;
81 cached_field_type= DRIZZLE_TYPE_DATETIME;
93 if (args[0]->
get_date(ltime, TIME_NO_ZERO_DATE))
99 if (date_sub_interval)
116 if (ltime.time_type == type::DRIZZLE_TIMESTAMP_DATE)
118 ltime.convert(*str, type::DRIZZLE_TIMESTAMP_DATE);
120 else if (ltime.second_part)
140 date = (ltime.year*100L + ltime.month)*100L + ltime.day;
142 return ltime.time_type == type::DRIZZLE_TIMESTAMP_DATE ? date :
143 ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
153 return ((int_type == other->int_type) &&
154 (date_sub_interval == other->date_sub_interval));
161 if (date_sub_interval)
163 str->append(STRING_WITH_LEN(
" - interval "));
167 str->append(STRING_WITH_LEN(
" + interval "));
171 str->append(interval_names[int_type], strlen(interval_names[int_type]));
virtual void print(String *str)
bool initFromItem(Item *args, interval_type int_type, String *str_value)
bool eq(const Item *item, bool binary_cmp) const
Stores time interval for date/time manipulation.
bool addDate(type::Time *ltime, interval_type int_type)
static const int MAX_STRING_LENGTH
bool get_date(type::Time &res, uint32_t fuzzy_date)
virtual void print(String *str)
String * val_str(String *)
bool eq(const Item *item, bool binary_cmp) const