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/function/time/now.h>
00023 #include <drizzled/current_session.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/session/times.h>
00026 #include <drizzled/temporal.h>
00027 #include <drizzled/field.h>
00028
00029 namespace drizzled {
00030
00031 String *Item_func_now::val_str(String *)
00032 {
00033 assert(fixed == 1);
00034 str_value.set(buff, buff_length, &my_charset_bin);
00035
00036 return &str_value;
00037 }
00038
00039
00040 void Item_func_now::fix_length_and_dec()
00041 {
00042 decimals= DATETIME_DEC;
00043 collation.set(&my_charset_bin);
00044
00045 ltime.reset();
00046
00047 ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
00048
00049 store_now_in_TIME(ltime);
00050
00051 ltime.convert(value);
00052
00053 size_t length= type::Time::MAX_STRING_LENGTH;
00054 ltime.convert(buff, length);
00055
00056 max_length= buff_length= length;
00057 }
00058
00063 void Item_func_now_local::store_now_in_TIME(type::Time &now_time)
00064 {
00065 Session *session= current_session;
00066 uint32_t fractional_seconds= 0;
00067 time_t tmp= session->times.getCurrentTimestampEpoch(fractional_seconds);
00068
00069 #if 0
00070 now_time->store(tmp, fractional_seconds, true);
00071 #endif
00072 now_time.store(tmp, fractional_seconds);
00073 }
00074
00075
00080 void Item_func_now_utc::store_now_in_TIME(type::Time &now_time)
00081 {
00082 uint32_t fractional_seconds= 0;
00083 time_t tmp= current_session->times.getCurrentTimestampEpoch(fractional_seconds);
00084 now_time.store(tmp, fractional_seconds);
00085 }
00086
00087 bool Item_func_now::get_temporal(DateTime &to)
00088 {
00089 to= cached_temporal;
00090 return true;
00091 }
00092
00093 bool Item_func_now::get_date(type::Time &res, uint32_t )
00094 {
00095 res= ltime;
00096 return 0;
00097 }
00098
00099
00100 int Item_func_now::save_in_field(Field *to, bool )
00101 {
00102 to->set_notnull();
00103 return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
00104 }
00105
00106 }