1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <boost/lexical_cast.hpp>
22
#include <drizzled/function/time/from_unixtime.h>
23
#include <drizzled/current_session.h>
24
#include <drizzled/session.h>
25
#include <drizzled/temporal.h>
26
#include <drizzled/time_functions.h>
34
void Item_func_from_unixtime::fix_length_and_dec()
36
session= current_session;
37
collation.set(&my_charset_bin);
38
decimals= DATETIME_DEC;
39
max_length=type::Time::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
43
String *Item_func_from_unixtime::val_str(String *str)
49
if (get_date(time_tmp, 0))
52
if (str->alloc(type::Time::MAX_STRING_LENGTH))
58
time_tmp.convert(*str);
63
int64_t Item_func_from_unixtime::val_int()
69
if (get_date(time_tmp, 0))
73
time_tmp.convert(ret);
78
bool Item_func_from_unixtime::get_date(type::Time <ime, uint32_t)
81
type::Time::usec_t fractional_tmp= 0;
83
switch (args[0]->result_type()) {
89
double double_tmp= args[0]->val_real();
91
tmp= (uint64_t)(double_tmp);
92
fractional_tmp= (type::Time::usec_t)((uint64_t)((double_tmp - tmp) * type::Time::FRACTIONAL_DIGITS) % type::Time::FRACTIONAL_DIGITS);
98
tmp= (uint64_t)(args[0]->val_int());
103
"tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
104
from_unixtime() argument since tmp is unsigned.
106
if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
110
ltime.store(tmp, fractional_tmp);
115
} /* namespace drizzled */