~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Stewart Smith
  • Date: 2009-03-04 22:49:53 UTC
  • mto: (910.4.2 sparc) (908.3.6 work)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: stewart@flamingspork.com-20090304224953-b2ow237kc1bkp0o0
for getopt, replace GET_ULONG with GET_UINT32.

Don't replace for sql variables (yet). instead just indicated the intense source of fail with GET_ULONG_IS_FAIL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/session.h"
24
 
#include "drizzled/temporal.h"
25
 
#include "drizzled/time_functions.h"
26
 
 
27
 
#include <sstream>
28
 
#include <string>
29
 
 
30
 
namespace drizzled
31
 
{
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/function/time/from_unixtime.h>
 
23
#include <drizzled/tztime.h>
 
24
#include <drizzled/session.h>
32
25
 
33
26
void Item_func_from_unixtime::fix_length_and_dec()
34
27
{
35
28
  session= current_session;
36
29
  collation.set(&my_charset_bin);
37
30
  decimals= DATETIME_DEC;
38
 
  max_length=DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
 
31
  max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
39
32
  maybe_null= 1;
40
33
}
41
34
 
71
64
  return (int64_t) TIME_to_uint64_t_datetime(&time_tmp);
72
65
}
73
66
 
74
 
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime, uint32_t)
 
67
bool Item_func_from_unixtime::get_date(DRIZZLE_TIME *ltime,
 
68
                                       uint32_t )
75
69
{
76
70
  uint64_t tmp= (uint64_t)(args[0]->val_int());
77
71
  /*
81
75
  if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
82
76
    return 1;
83
77
 
84
 
  Timestamp temporal;
85
 
  if (! temporal.from_time_t((time_t) tmp))
86
 
  {
87
 
    null_value= true;
88
 
    std::string tmp_string(boost::lexical_cast<std::string>(tmp));
89
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), tmp_string.c_str());
90
 
    return 0;
91
 
  }
92
 
  
93
 
  memset(ltime, 0, sizeof(*ltime));
94
 
 
95
 
  ltime->year= temporal.years();
96
 
  ltime->month= temporal.months();
97
 
  ltime->day= temporal.days();
98
 
  ltime->hour= temporal.hours();
99
 
  ltime->minute= temporal.minutes();
100
 
  ltime->second= temporal.seconds();
101
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
78
  session->variables.time_zone->gmt_sec_to_TIME(ltime, (time_t)tmp);
102
79
 
103
80
  return 0;
104
81
}
105
82
 
106
 
} /* namespace drizzled */
 
83