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