00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/function/func.h>
00023 #include <drizzled/function/str/strfunc.h>
00024 #include <drizzled/temporal.h>
00025
00026 namespace drizzled
00027 {
00028
00029
00030 class Item_date :public Item_func
00031 {
00032 public:
00033 using Item_func::tmp_table_field;
00034
00035 Item_date() :Item_func() {}
00036 Item_date(Item *a) :Item_func(a) {}
00037 enum Item_result result_type () const { return STRING_RESULT; }
00038 enum_field_types field_type() const { return DRIZZLE_TYPE_DATE; }
00039 String *val_str(String *str);
00040 int64_t val_int();
00041 double val_real() { return val_real_from_decimal(); }
00042 const char *func_name() const { return "date"; }
00043 void fix_length_and_dec()
00044 {
00045 collation.set(&my_charset_bin);
00046 decimals=0;
00047 max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
00048 }
00060 virtual bool get_temporal(Date &temporal)= 0;
00061 Field *tmp_table_field(Table *table)
00062 {
00063 return tmp_table_field_from_field_type(table, 0);
00064 }
00065 bool result_as_int64_t() { return true; }
00066 type::Decimal *val_decimal(type::Decimal *decimal_value)
00067 {
00068 assert(fixed == 1);
00069 return val_decimal_from_date(decimal_value);
00070 }
00071 int save_in_field(Field *field,
00072 bool )
00073 {
00074 return save_date_in_field(field);
00075 }
00076 };
00077
00078 class Item_date_func :public Item_str_func
00079 {
00080 public:
00081 Item_date_func() :Item_str_func() {}
00082 Item_date_func(Item *a) :Item_str_func(a) {}
00083 Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
00084 Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
00085 enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
00086
00087 using Item_func::tmp_table_field;
00088 Field *tmp_table_field(Table *table)
00089 {
00090 return tmp_table_field_from_field_type(table, 0);
00091 }
00092 bool result_as_int64_t() { return true; }
00093 double val_real() { return (double) val_int(); }
00094 type::Decimal *val_decimal(type::Decimal *decimal_value)
00095 {
00096 assert(fixed == 1);
00097 return val_decimal_from_date(decimal_value);
00098 }
00099 int save_in_field(Field *field,
00100 bool )
00101 {
00102 return save_date_in_field(field);
00103 }
00104 };
00105
00106 }
00107