~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/date.cc

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
  DateTime temporal;
75
75
  if (! temporal.from_string(from, (size_t) len))
76
76
  {
77
 
    my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), from);
 
77
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), from);
78
78
    return 2;
79
79
  }
80
80
  /* Create the stored integer format. @TODO This should go away. Should be up to engine... */
94
94
    ss.precision(18); /* 18 places should be fine for error display of double input. */
95
95
    ss << from; ss >> tmp;
96
96
 
97
 
    my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
97
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
98
98
    return 2;
99
99
  }
100
100
  return Field_date::store((int64_t) rint(from), false);
113
113
    /* Convert the integer to a string using boost::lexical_cast */
114
114
    std::string tmp(boost::lexical_cast<std::string>(from)); 
115
115
 
116
 
    my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
116
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
117
117
    return 2;
118
118
  }
119
119
 
120
120
  /* Create the stored integer format. @TODO This should go away. Should be up to engine... */
121
121
  uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
122
122
  int4store(ptr, int_value);
123
 
 
124
123
  return 0;
125
124
}
126
125
 
127
 
int Field_date::store_time(type::Time &ltime,
128
 
                           type::timestamp_t time_type)
 
126
int Field_date::store_time(DRIZZLE_TIME *ltime,
 
127
                              enum enum_drizzle_timestamp_type time_type)
129
128
{
130
129
  long tmp;
131
130
  int error= 0;
132
 
  if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
 
131
  if (time_type == DRIZZLE_TIMESTAMP_DATE ||
 
132
      time_type == DRIZZLE_TIMESTAMP_DATETIME)
133
133
  {
134
 
    tmp= ltime.year*10000 + ltime.month*100 + ltime.day;
135
 
 
136
 
    Session *session= getTable() ? getTable()->in_use : current_session;
137
 
    type::cut_t cut_error= type::VALID;
138
 
    if (ltime.check(tmp != 0,
139
 
                     (TIME_FUZZY_DATE |
140
 
                      (session->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), cut_error))
 
134
    tmp= ltime->year*10000 + ltime->month*100 + ltime->day;
 
135
    if (check_date(ltime, tmp != 0,
 
136
                   (TIME_FUZZY_DATE |
 
137
                    (current_session->variables.sql_mode &
 
138
                     (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
141
139
    {
142
 
      char buff[type::Time::MAX_STRING_LENGTH];
 
140
      char buff[MAX_DATE_STRING_REP_LENGTH];
143
141
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
144
 
      ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
 
142
      make_date(ltime, &str);
145
143
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
146
 
                           str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
 
144
                           str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
147
145
    }
148
 
 
149
 
    error= static_cast<int>(cut_error);
150
 
 
151
 
    if (not error && ltime.time_type != type::DRIZZLE_TIMESTAMP_DATE &&
152
 
        (ltime.hour || ltime.minute || ltime.second || ltime.second_part))
 
146
    if (!error && ltime->time_type != DRIZZLE_TIMESTAMP_DATE &&
 
147
        (ltime->hour || ltime->minute || ltime->second || ltime->second_part))
153
148
    {
154
 
      char buff[type::Time::MAX_STRING_LENGTH];
 
149
      char buff[MAX_DATE_STRING_REP_LENGTH];
155
150
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
156
 
      ltime.convert(str);
 
151
      make_datetime(ltime, &str);
157
152
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
158
153
                           ER_WARN_DATA_TRUNCATED,
159
 
                           str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
 
154
                           str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
160
155
      error= 3;
161
156
    }
162
157
  }
166
161
    error= 1;
167
162
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
168
163
  }
169
 
 
170
164
  int4store(ptr,tmp);
171
 
 
172
165
  return error;
173
166
}
174
167
 
216
209
  return val_buffer;
217
210
}
218
211
 
219
 
bool Field_date::get_date(type::Time &ltime, uint32_t fuzzydate)
 
212
bool Field_date::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
220
213
{
221
214
  uint32_t tmp=(uint32_t) uint4korr(ptr);
222
 
  ltime.day=            (int) (tmp%100);
223
 
  ltime.month=  (int) (tmp/100%100);
224
 
  ltime.year=           (int) (tmp/10000);
225
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
226
 
  ltime.hour= ltime.minute= ltime.second= ltime.second_part= ltime.neg= 0;
227
 
 
228
 
  return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ?
 
215
  ltime->day=           (int) (tmp%100);
 
216
  ltime->month=         (int) (tmp/100%100);
 
217
  ltime->year=          (int) (tmp/10000);
 
218
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
 
219
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
 
220
  return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
229
221
          1 : 0);
230
222
}
231
223
 
232
 
bool Field_date::get_time(type::Time &ltime)
 
224
bool Field_date::get_time(DRIZZLE_TIME *ltime)
233
225
{
234
 
  return Field_date::get_date(ltime ,0);
 
226
  return Field_date::get_date(ltime,0);
235
227
}
236
228
 
237
229
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)