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
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
22
#include "drizzled/function/time/from_unixtime.h"
23
#include "drizzled/session.h"
24
#include "drizzled/temporal.h"
25
#include "drizzled/time_functions.h"
33
void Item_func_from_unixtime::fix_length_and_dec()
35
session= current_session;
36
collation.set(&my_charset_bin);
37
decimals= DATETIME_DEC;
38
max_length=DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
42
String *Item_func_from_unixtime::val_str(String *str)
44
DRIZZLE_TIME time_tmp;
48
if (get_date(&time_tmp, 0))
51
if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
57
make_datetime(&time_tmp, str);
62
int64_t Item_func_from_unixtime::val_int()
64
DRIZZLE_TIME time_tmp;
68
if (get_date(&time_tmp, 0))
71
return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
74
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime, uint32_t)
76
uint64_t tmp= (uint64_t)(args[0]->val_int());
78
"tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
79
from_unixtime() argument since tmp is unsigned.
81
if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
85
if (! temporal.from_time_t((time_t) tmp))
89
std::string tmp_string;
90
ss << tmp; ss >> tmp_string;
91
my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), tmp_string.c_str());
95
memset(ltime, 0, sizeof(*ltime));
97
ltime->year= temporal.years();
98
ltime->month= temporal.months();
99
ltime->day= temporal.days();
100
ltime->hour= temporal.hours();
101
ltime->minute= temporal.minutes();
102
ltime->second= temporal.seconds();
103
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
108
} /* namespace drizzled */