~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-01-19 18:03:32 UTC
  • mfrom: (2088.8.12 timestamp)
  • mto: This revision was merged to the branch mainline in revision 2098.
  • Revision ID: brian@tangent.org-20110119180332-acfk5i8oofp63s40
Merge in time code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
  if (get_date(&time_tmp, 0))
49
49
    return 0;
50
50
 
51
 
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
 
51
  if (str->alloc(type::Time::MAX_STRING_LENGTH))
52
52
  {
53
53
    null_value= 1;
54
54
    return 0;
55
55
  }
56
56
 
57
 
  make_datetime(&time_tmp, str);
 
57
  time_tmp.convert(*str);
58
58
 
59
59
  return str;
60
60
}
73
73
 
74
74
bool Item_func_from_unixtime::get_date(type::Time *ltime, uint32_t)
75
75
{
76
 
  uint64_t tmp= (uint64_t)(args[0]->val_int());
 
76
  uint64_t tmp= 0;
 
77
  type::Time::usec_t fractional_tmp= 0;
 
78
 
 
79
  switch (args[0]->result_type()) {
 
80
  case REAL_RESULT:
 
81
  case ROW_RESULT:
 
82
  case DECIMAL_RESULT:
 
83
  case STRING_RESULT:
 
84
    {
 
85
      double double_tmp= args[0]->val_real();
 
86
 
 
87
      tmp= (uint64_t)(double_tmp);
 
88
      fractional_tmp=  (type::Time::usec_t)((double_tmp - tmp) * 1000000);
 
89
 
 
90
      break;
 
91
    }
 
92
  case INT_RESULT:
 
93
    tmp= (uint64_t)(args[0]->val_int());
 
94
    break;
 
95
  }
 
96
 
77
97
  /*
78
98
    "tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
79
99
    from_unixtime() argument since tmp is unsigned.
81
101
  if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
82
102
    return 1;
83
103
 
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;
 
104
  ltime->reset();
 
105
  ltime->store(tmp, fractional_tmp);
102
106
 
103
107
  return 0;
104
108
}