~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/epoch.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:11:45 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051145-xiputq4lvmtct377
storage engine docs. add bit about some temp table only engines.

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_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
 
165
    my_error(ER_INVALID_UNIX_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
 
  uint64_t from_tmp= (uint64_t)from;
182
 
 
183
 
  Timestamp temporal;
184
 
  if (not temporal.from_int64_t(from_tmp))
 
181
  if (from < 0 || from > 99991231235959.0)
185
182
  {
186
 
    /* Convert the integer to a string using boost::lexical_cast */
187
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
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;
188
189
 
189
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
190
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
190
191
    return 2;
191
192
  }
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);
 
193
  return Epoch::store((int64_t) rint(from), false);
208
194
}
209
195
 
210
196
int Epoch::store(int64_t from, bool)
216
202
   * if unable to create a valid DateTime.  
217
203
   */
218
204
  Timestamp temporal;
219
 
  if (not temporal.from_int64_t(from))
 
205
  if (! temporal.from_int64_t(from))
220
206
  {
221
207
    /* Convert the integer to a string using boost::lexical_cast */
222
208
    std::string tmp(boost::lexical_cast<std::string>(from));
223
209
 
224
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
210
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
225
211
    return 2;
226
212
  }
227
213
 
280
266
  return val_buffer;
281
267
}
282
268
 
283
 
bool Epoch::get_date(type::Time &ltime, uint32_t)
 
269
bool Epoch::get_date(type::Time *ltime, uint32_t)
284
270
{
285
271
  uint64_t temp;
286
 
  type::Time::epoch_t time_temp;
287
272
 
288
273
  unpack_num(temp);
289
 
  time_temp= temp;
290
274
  
291
 
  ltime.reset();
292
 
 
293
 
  ltime.store(time_temp);
 
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();
294
289
 
295
290
  return 0;
296
291
}
297
292
 
298
 
bool Epoch::get_time(type::Time &ltime)
 
293
bool Epoch::get_time(type::Time *ltime)
299
294
{
300
 
  return Epoch::get_date(ltime, 0);
 
295
  return Epoch::get_date(ltime,0);
301
296
}
302
297
 
303
298
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)