~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/datetime.cc

  • Committer: Monty Taylor
  • Date: 2009-03-05 02:06:48 UTC
  • mfrom: (907.1.8 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090305020648-7jk1gie4lqsi22g8
Merged from Jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
                          uint32_t len,
46
46
                          const CHARSET_INFO * const )
47
47
{
48
 
#ifdef NOTDEFINED
49
 
  DRIZZLE_TIME time_tmp;
50
 
  int error;
51
 
  uint64_t tmp= 0;
52
 
  enum enum_drizzle_timestamp_type func_res;
53
 
  Session *session= table ? table->in_use : current_session;
54
 
 
55
 
  func_res= str_to_datetime(from, len, &time_tmp,
56
 
                            (TIME_FUZZY_DATE |
57
 
                             (session->variables.sql_mode &
58
 
                              (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
59
 
                            &error);
60
 
  if ((int) func_res > (int) DRIZZLE_TIMESTAMP_ERROR)
61
 
    tmp= TIME_to_uint64_t_datetime(&time_tmp);
62
 
  else
63
 
    error= 1;                                 // Fix if invalid zero date
64
 
 
65
 
  if (error)
66
 
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
67
 
                         ER_WARN_DATA_OUT_OF_RANGE,
68
 
                         from, len, DRIZZLE_TIMESTAMP_DATETIME, 1);
69
 
 
70
 
#ifdef WORDS_BIGENDIAN
71
 
  if (table && table->s->db_low_byte_first)
72
 
  {
73
 
    int8store(ptr,tmp);
74
 
  }
75
 
  else
76
 
#endif
77
 
    int64_tstore(ptr,tmp);
78
 
#endif /* NOTDEFINED */
79
48
  /* 
80
49
   * Try to create a DateTime from the supplied string.  Throw an error
81
50
   * if unable to create a valid DateTime.  
154
123
  return 0;
155
124
}
156
125
 
157
 
int Field_datetime::store_time(DRIZZLE_TIME *ltime,
158
 
                               enum enum_drizzle_timestamp_type time_type)
 
126
int Field_datetime::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
159
127
{
160
 
  int64_t tmp;
161
 
  int error= 0;
162
 
  /*
163
 
    We don't perform range checking here since values stored in TIME
164
 
    structure always fit into DATETIME range.
165
 
  */
166
 
  if (time_type == DRIZZLE_TIMESTAMP_DATE ||
167
 
      time_type == DRIZZLE_TIMESTAMP_DATETIME)
168
 
  {
169
 
    tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*INT64_C(1000000)+
170
 
         (ltime->hour*10000L+ltime->minute*100+ltime->second));
171
 
    if (check_date(ltime, tmp != 0,
172
 
                   (TIME_FUZZY_DATE |
173
 
                    (current_session->variables.sql_mode &
174
 
                     (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
175
 
    {
176
 
      char buff[MAX_DATE_STRING_REP_LENGTH];
177
 
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
178
 
      make_datetime(ltime, &str);
179
 
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
180
 
                           str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATETIME,1);
181
 
    }
182
 
  }
183
 
  else
184
 
  {
185
 
    tmp=0;
186
 
    error= 1;
187
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
188
 
  }
 
128
  drizzled::DateTime temporal;
 
129
 
 
130
  temporal.set_years(ltime->year);
 
131
  temporal.set_months(ltime->month);
 
132
  temporal.set_days(ltime->day);
 
133
  temporal.set_hours(ltime->hour);
 
134
  temporal.set_minutes(ltime->minute);
 
135
  temporal.set_seconds(ltime->second);
 
136
 
 
137
  if (! temporal.is_valid())
 
138
  {
 
139
    char tmp_string[MAX_DATE_STRING_REP_LENGTH];
 
140
    size_t tmp_string_len;
 
141
 
 
142
    temporal.to_string(tmp_string, &tmp_string_len);
 
143
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp_string);
 
144
    return 1;
 
145
  }
 
146
 
 
147
  int64_t int_value;
 
148
  temporal.to_int64_t(&int_value);
 
149
 
189
150
#ifdef WORDS_BIGENDIAN
190
151
  if (table && table->s->db_low_byte_first)
191
152
  {
192
 
    int8store(ptr,tmp);
 
153
    int8store(ptr, int_value);
193
154
  }
194
155
  else
195
156
#endif
196
 
    int64_tstore(ptr,tmp);
197
 
  return error;
 
157
    int64_tstore(ptr, int_value);
 
158
  return 0;
198
159
}
199
160
 
200
161
double Field_datetime::val_real(void)