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/sysdate_local.h> 00023 #include <drizzled/tztime.h> 00024 #include <drizzled/session.h> 00025 #include <drizzled/field.h> 00026 00027 namespace drizzled { 00028 00033 void Item_func_sysdate_local::store_now_in_TIME(type::Time &now_time) 00034 { 00035 getSession().variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL)); 00036 } 00037 00038 00039 String *Item_func_sysdate_local::val_str(String *) 00040 { 00041 assert(fixed == 1); 00042 store_now_in_TIME(ltime); 00043 00044 size_t length= type::Time::MAX_STRING_LENGTH; 00045 ltime.convert(buff, length); 00046 buff_length= length; 00047 str_value.set(buff, length, &my_charset_bin); 00048 00049 return &str_value; 00050 } 00051 00052 00053 int64_t Item_func_sysdate_local::val_int() 00054 { 00055 assert(fixed == 1); 00056 store_now_in_TIME(ltime); 00057 int64_t tmp; 00058 ltime.convert(tmp); 00059 00060 return tmp; 00061 } 00062 00063 double Item_func_sysdate_local::val_real() 00064 { 00065 assert(fixed == 1); 00066 00067 store_now_in_TIME(ltime); 00068 int64_t tmp; 00069 ltime.convert(tmp); 00070 00071 return int64_t2double(tmp); 00072 } 00073 00074 00075 void Item_func_sysdate_local::fix_length_and_dec() 00076 { 00077 decimals= 0; 00078 collation.set(&my_charset_bin); 00079 max_length= DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN; 00080 } 00081 00082 00083 bool Item_func_sysdate_local::get_date(type::Time &res, uint32_t ) 00084 { 00085 store_now_in_TIME(ltime); 00086 res= ltime; 00087 return 0; 00088 } 00089 00090 00091 int Item_func_sysdate_local::save_in_field(Field *to, bool ) 00092 { 00093 store_now_in_TIME(ltime); 00094 to->set_notnull(); 00095 to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME); 00096 00097 return 0; 00098 } 00099 00100 } /* namespace drizzled */