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 #include <boost/lexical_cast.hpp> 00022 #include <drizzled/function/time/from_days.h> 00023 #include <drizzled/error.h> 00024 #include <drizzled/temporal.h> 00025 00026 #include <sstream> 00027 #include <string> 00028 00029 namespace drizzled 00030 { 00031 00036 bool Item_func_from_days::get_temporal(Date &to) 00037 { 00038 assert(fixed); 00039 00040 /* 00041 * We MUST call val_int() before checking null_value because, stupidly, 00042 * a subselect does not evaluate it's scalar items as null until val_xxx() 00043 * has been called. :( 00044 */ 00045 int64_t int_value= args[0]->val_int(); 00046 00047 /* We return NULL from FROM_DAYS() only when supplied a NULL argument */ 00048 if (args[0]->null_value) 00049 { 00050 null_value= true; 00051 return false; 00052 } 00053 00054 /* OK, now try to convert from our integer */ 00055 if (! to.from_julian_day_number(int_value)) 00056 { 00057 /* Bad input, throw an error */ 00058 std::string tmp(boost::lexical_cast<std::string>(int_value)); 00059 00060 my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(ME_FATALERROR), tmp.c_str(), func_name()); 00061 return false; 00062 } 00063 return true; 00064 } 00065 00066 } /* namespace drizzled */