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/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 } /* namespace drizzled */