~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/epoch.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:
162
162
 
163
163
  if (not temporal.from_string(from, (size_t) len))
164
164
  {
165
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
 
165
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
166
166
    return 1;
167
167
  }
168
168
 
178
178
{
179
179
  ASSERT_COLUMN_MARKED_FOR_WRITE;
180
180
 
181
 
  if (from < 0 || from > 99991231235959.0)
 
181
  uint64_t from_tmp= (uint64_t)from;
 
182
 
 
183
  Timestamp temporal;
 
184
  if (not temporal.from_int64_t(from_tmp))
182
185
  {
183
 
    /* Convert the double to a string using stringstream */
184
 
    std::stringstream ss;
185
 
    std::string tmp;
186
 
    ss.precision(18); /* 18 places should be fine for error display of double input. */
187
 
    ss << from; 
188
 
    ss >> tmp;
 
186
    /* Convert the integer to a string using boost::lexical_cast */
 
187
    std::string tmp(boost::lexical_cast<std::string>(from));
189
188
 
190
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
189
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
191
190
    return 2;
192
191
  }
193
 
  return Epoch::store((int64_t) rint(from), false);
 
192
 
 
193
  time_t tmp;
 
194
  temporal.to_time_t(tmp);
 
195
 
 
196
  uint64_t tmp_micro= tmp;
 
197
  pack_num(tmp_micro);
 
198
 
 
199
  return 0;
 
200
}
 
201
 
 
202
int Epoch::store_decimal(const type::Decimal *value)
 
203
{
 
204
  double tmp;
 
205
  value->convert(tmp);
 
206
 
 
207
  return store(tmp);
194
208
}
195
209
 
196
210
int Epoch::store(int64_t from, bool)
202
216
   * if unable to create a valid DateTime.  
203
217
   */
204
218
  Timestamp temporal;
205
 
  if (! temporal.from_int64_t(from))
 
219
  if (not temporal.from_int64_t(from))
206
220
  {
207
221
    /* Convert the integer to a string using boost::lexical_cast */
208
222
    std::string tmp(boost::lexical_cast<std::string>(from));
209
223
 
210
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
224
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
211
225
    return 2;
212
226
  }
213
227
 
269
283
bool Epoch::get_date(type::Time *ltime, uint32_t)
270
284
{
271
285
  uint64_t temp;
 
286
  type::Time::epoch_t time_temp;
272
287
 
273
288
  unpack_num(temp);
 
289
  time_temp= temp;
274
290
  
275
 
  memset(ltime, 0, sizeof(*ltime));
276
 
 
277
 
  Timestamp temporal;
278
 
  (void) temporal.from_time_t((time_t) temp);
279
 
 
280
 
  /* @TODO Goodbye the below code when type::Time is finally gone.. */
281
 
 
282
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
283
 
  ltime->year= temporal.years();
284
 
  ltime->month= temporal.months();
285
 
  ltime->day= temporal.days();
286
 
  ltime->hour= temporal.hours();
287
 
  ltime->minute= temporal.minutes();
288
 
  ltime->second= temporal.seconds();
 
291
  ltime->reset();
 
292
 
 
293
  ltime->store(time_temp);
289
294
 
290
295
  return 0;
291
296
}
292
297
 
293
298
bool Epoch::get_time(type::Time *ltime)
294
299
{
295
 
  return Epoch::get_date(ltime,0);
 
300
  return Epoch::get_date(ltime, 0);
296
301
}
297
302
 
298
303
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)