~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/time/from_unixtime.cc

  • Committer: Monty Taylor
  • Date: 2008-12-06 22:41:03 UTC
  • mto: (656.1.7 devel)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: monty@inaugust.com-20081206224103-jdouqwt9hb0f01y1
Moved non-working tests into broken suite for easier running of working tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
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
18
18
 */
19
19
 
20
 
#include <config.h>
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>
 
21
#include CSTDINT_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>
27
 
 
28
 
#include <sstream>
29
 
#include <string>
30
 
 
31
 
namespace drizzled
32
 
{
33
27
 
34
28
void Item_func_from_unixtime::fix_length_and_dec()
35
29
{
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;
40
34
  maybe_null= 1;
41
35
}
42
36
 
43
37
String *Item_func_from_unixtime::val_str(String *str)
44
38
{
45
 
  type::Time time_tmp;
 
39
  DRIZZLE_TIME time_tmp;
46
40
 
47
41
  assert(fixed == 1);
48
42
 
49
 
  if (get_date(time_tmp, 0))
 
43
  if (get_date(&time_tmp, 0))
50
44
    return 0;
51
45
 
52
 
  if (str->alloc(type::Time::MAX_STRING_LENGTH))
 
46
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
53
47
  {
54
48
    null_value= 1;
55
49
    return 0;
56
50
  }
57
51
 
58
 
  time_tmp.convert(*str);
 
52
  make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
59
53
 
60
54
  return str;
61
55
}
62
56
 
63
57
int64_t Item_func_from_unixtime::val_int()
64
58
{
65
 
  type::Time time_tmp;
 
59
  DRIZZLE_TIME time_tmp;
66
60
 
67
61
  assert(fixed == 1);
68
62
 
69
 
  if (get_date(time_tmp, 0))
 
63
  if (get_date(&time_tmp, 0))
70
64
    return 0;
71
65
 
72
 
  int64_t ret;
73
 
  time_tmp.convert(ret);
74
 
 
75
 
  return (int64_t) ret;
 
66
  return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
76
67
}
77
68
 
78
 
bool Item_func_from_unixtime::get_date(type::Time &ltime, uint32_t)
 
69
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
 
70
                                       uint32_t fuzzy_date __attribute__((unused)))
79
71
{
80
 
  uint64_t tmp= 0;
81
 
  type::Time::usec_t fractional_tmp= 0;
82
 
 
83
 
  switch (args[0]->result_type()) {
84
 
  case REAL_RESULT:
85
 
  case ROW_RESULT:
86
 
  case DECIMAL_RESULT:
87
 
  case STRING_RESULT:
88
 
    {
89
 
      double double_tmp= args[0]->val_real();
90
 
 
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);
93
 
 
94
 
      break;
95
 
    }
96
 
 
97
 
  case INT_RESULT:
98
 
    tmp= (uint64_t)(args[0]->val_int());
99
 
    break;
100
 
  }
101
 
 
 
72
  uint64_t tmp= (uint64_t)(args[0]->val_int());
102
73
  /*
103
74
    "tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
104
75
    from_unixtime() argument since tmp is unsigned.
106
77
  if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
107
78
    return 1;
108
79
 
109
 
  ltime.reset();
110
 
  ltime.store(tmp, fractional_tmp);
 
80
  session->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)tmp);
111
81
 
112
82
  return 0;
113
83
}
114
84
 
115
 
} /* namespace drizzled */
 
85