1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
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>
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/time/from_unixtime.h>
23
#include <drizzled/functions/time/make_datetime.h>
24
#include <drizzled/item/timefunc.h>
25
#include <drizzled/tztime.h>
24
26
#include <drizzled/session.h>
25
#include <drizzled/temporal.h>
26
#include <drizzled/time_functions.h>
34
28
void Item_func_from_unixtime::fix_length_and_dec()
36
30
session= current_session;
37
31
collation.set(&my_charset_bin);
38
32
decimals= DATETIME_DEC;
39
max_length=type::Time::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
33
max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
43
37
String *Item_func_from_unixtime::val_str(String *str)
39
DRIZZLE_TIME time_tmp;
47
41
assert(fixed == 1);
49
if (get_date(time_tmp, 0))
43
if (get_date(&time_tmp, 0))
52
if (str->alloc(type::Time::MAX_STRING_LENGTH))
46
if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
58
time_tmp.convert(*str);
52
make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
63
57
int64_t Item_func_from_unixtime::val_int()
59
DRIZZLE_TIME time_tmp;
67
61
assert(fixed == 1);
69
if (get_date(time_tmp, 0))
63
if (get_date(&time_tmp, 0))
73
time_tmp.convert(ret);
66
return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
78
bool Item_func_from_unixtime::get_date(type::Time <ime, uint32_t)
69
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
70
uint32_t fuzzy_date __attribute__((unused)))
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());
72
uint64_t tmp= (uint64_t)(args[0]->val_int());
103
74
"tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
104
75
from_unixtime() argument since tmp is unsigned.