~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/date.cc

  • Committer: Brian Aker
  • Date: 2011-01-25 07:22:15 UTC
  • mfrom: (2109.1.7 drizzle-build)
  • Revision ID: brian@tangent.org-20110125072215-567z6uzy5vdvn4va
Merge in build/timestamp patches/fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
  return 0;
124
124
}
125
125
 
126
 
int Field_date::store_time(type::Time *ltime,
 
126
int Field_date::store_time(type::Time &ltime,
127
127
                           type::timestamp_t time_type)
128
128
{
129
129
  long tmp;
130
130
  int error= 0;
131
131
  if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
132
132
  {
133
 
    tmp= ltime->year*10000 + ltime->month*100 + ltime->day;
 
133
    tmp= ltime.year*10000 + ltime.month*100 + ltime.day;
134
134
 
135
 
    if (ltime->check(tmp != 0,
 
135
    type::cut_t cut_error= type::VALID;
 
136
    if (ltime.check(tmp != 0,
136
137
                     (TIME_FUZZY_DATE |
137
138
                      (current_session->variables.sql_mode &
138
 
                       (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
 
139
                       (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), cut_error))
139
140
    {
140
141
      char buff[type::Time::MAX_STRING_LENGTH];
141
142
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
142
 
      ltime->convert(str, type::DRIZZLE_TIMESTAMP_DATE);
 
143
      ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
143
144
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
144
145
                           str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
145
146
    }
146
147
 
147
 
    if (not error && ltime->time_type != type::DRIZZLE_TIMESTAMP_DATE &&
148
 
        (ltime->hour || ltime->minute || ltime->second || ltime->second_part))
 
148
    error= static_cast<int>(cut_error);
 
149
 
 
150
    if (not error && ltime.time_type != type::DRIZZLE_TIMESTAMP_DATE &&
 
151
        (ltime.hour || ltime.minute || ltime.second || ltime.second_part))
149
152
    {
150
153
      char buff[type::Time::MAX_STRING_LENGTH];
151
154
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
152
 
      ltime->convert(str);
 
155
      ltime.convert(str);
153
156
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
154
157
                           ER_WARN_DATA_TRUNCATED,
155
158
                           str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
212
215
  return val_buffer;
213
216
}
214
217
 
215
 
bool Field_date::get_date(type::Time *ltime,uint32_t fuzzydate)
 
218
bool Field_date::get_date(type::Time &ltime, uint32_t fuzzydate)
216
219
{
217
220
  uint32_t tmp=(uint32_t) uint4korr(ptr);
218
 
  ltime->day=           (int) (tmp%100);
219
 
  ltime->month=         (int) (tmp/100%100);
220
 
  ltime->year=          (int) (tmp/10000);
221
 
  ltime->time_type= type::DRIZZLE_TIMESTAMP_DATE;
222
 
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
223
 
  return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
 
221
  ltime.day=            (int) (tmp%100);
 
222
  ltime.month=  (int) (tmp/100%100);
 
223
  ltime.year=           (int) (tmp/10000);
 
224
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
 
225
  ltime.hour= ltime.minute= ltime.second= ltime.second_part= ltime.neg= 0;
 
226
 
 
227
  return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ?
224
228
          1 : 0);
225
229
}
226
230
 
227
 
bool Field_date::get_time(type::Time *ltime)
 
231
bool Field_date::get_time(type::Time &ltime)
228
232
{
229
 
  return Field_date::get_date(ltime,0);
 
233
  return Field_date::get_date(ltime ,0);
230
234
}
231
235
 
232
236
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)