Drizzled Public API Documentation

curdate.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/curdate.h>
00023 #include <drizzled/temporal.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/session/times.h>
00026 #include <drizzled/current_session.h>
00027 
00028 namespace drizzled
00029 {
00030 
00031 void Item_func_curdate::fix_length_and_dec()
00032 {
00033   collation.set(&my_charset_bin);
00034   decimals=0;
00035   max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
00036 
00037   store_now_in_TIME(&ltime);
00038 
00039   /* We don't need to set second_part and neg because they already 0 */
00040   ltime.hour= ltime.minute= ltime.second= 0;
00041   ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
00042 
00047   cached_temporal.set_years(ltime.year);
00048   cached_temporal.set_months(ltime.month);
00049   cached_temporal.set_days(ltime.day);
00050 }
00051 
00056 void Item_func_curdate_local::store_now_in_TIME(type::Time *now_time)
00057 {
00058   (void) cached_temporal.from_time_t(current_session->times.getCurrentTimestampEpoch());
00059 
00060   now_time->year= cached_temporal.years();
00061   now_time->month= cached_temporal.months();
00062   now_time->day= cached_temporal.days();
00063   now_time->hour= 0;
00064   now_time->minute= 0;
00065   now_time->second= 0;
00066   now_time->second_part= 0;
00067 }
00068 
00073 void Item_func_curdate_utc::store_now_in_TIME(type::Time *now_time)
00074 {
00075   (void) cached_temporal.from_time_t(current_session->times.getCurrentTimestampEpoch());
00076 
00077   now_time->year= cached_temporal.years();
00078   now_time->month= cached_temporal.months();
00079   now_time->day= cached_temporal.days();
00080   now_time->hour= 0;
00081   now_time->minute= 0;
00082   now_time->second= 0;
00083   now_time->second_part= 0;
00084 }
00085 
00086 bool Item_func_curdate::get_temporal(Date &to)
00087 {
00088   to= cached_temporal;
00089   return true;
00090 }
00091 
00092 } /* namespace drizzled */