Drizzled Public API Documentation

now.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } /* namespace drizzled */