~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

Fix for 64bit issue around timestamp

Show diffs side-by-side

added added

removed removed

Lines of Context:
229
229
 
230
230
int64_t Field_timestamp::val_int(void)
231
231
{
232
 
  uint32_t temp;
 
232
  uint64_t temp;
233
233
 
234
234
  ASSERT_COLUMN_MARKED_FOR_READ;
235
235
 
236
236
#ifdef WORDS_BIGENDIAN
237
237
  if (getTable() && getTable()->s->db_low_byte_first)
238
 
    temp= uint4korr(ptr);
 
238
    temp= uint8korr(ptr);
239
239
  else
240
240
#endif
241
 
    longget(temp, ptr);
 
241
    int64_tget(temp, ptr);
242
242
 
243
243
  Timestamp temporal;
244
244
  (void) temporal.from_time_t((time_t) temp);
251
251
 
252
252
String *Field_timestamp::val_str(String *val_buffer, String *)
253
253
{
254
 
  uint32_t temp;
 
254
  uint64_t temp;
255
255
  char *to;
256
256
  int to_len= field_length + 1;
257
257
 
260
260
 
261
261
#ifdef WORDS_BIGENDIAN
262
262
  if (getTable() && getTable()->s->db_low_byte_first)
263
 
    temp= uint4korr(ptr);
 
263
    temp= uint8korr(ptr);
264
264
  else
265
265
#endif
266
 
    longget(temp, ptr);
 
266
    int64_tget(temp, ptr);
267
267
 
268
268
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
269
269
 
280
280
 
281
281
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t)
282
282
{
283
 
  uint32_t temp;
 
283
  uint64_t temp;
284
284
 
285
285
#ifdef WORDS_BIGENDIAN
286
286
  if (getTable() && getTable()->s->db_low_byte_first)
287
 
    temp= uint4korr(ptr);
 
287
    temp= uint8korr(ptr);
288
288
  else
289
289
#endif
290
 
    longget(temp, ptr);
 
290
    int64_tget(temp, ptr);
291
291
  
292
292
  memset(ltime, 0, sizeof(*ltime));
293
293
 
314
314
 
315
315
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
316
316
{
317
 
  int32_t a,b;
 
317
  int64_t a,b;
318
318
#ifdef WORDS_BIGENDIAN
319
319
  if (getTable() && getTable()->s->db_low_byte_first)
320
320
  {
321
 
    a=sint4korr(a_ptr);
322
 
    b=sint4korr(b_ptr);
 
321
    a=sint8korr(a_ptr);
 
322
    b=sint8korr(b_ptr);
323
323
  }
324
324
  else
325
325
#endif
326
326
  {
327
 
  longget(a,a_ptr);
328
 
  longget(b,b_ptr);
 
327
    int64_tget(a, a_ptr);
 
328
    int64_tget(b, b_ptr);
329
329
  }
330
 
  return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
 
330
  return ((uint64_t) a < (uint64_t) b) ? -1 : ((uint64_t) a > (uint64_t) b) ? 1 : 0;
331
331
}
332
332
 
333
333
 
340
340
    to[1] = ptr[1];
341
341
    to[2] = ptr[2];
342
342
    to[3] = ptr[3];
 
343
    to[4] = ptr[4];
 
344
    to[5] = ptr[5];
 
345
    to[6] = ptr[6];
 
346
    to[7] = ptr[7];
343
347
  }
344
348
  else
345
349
#endif
346
350
  {
347
 
    to[0] = ptr[3];
348
 
    to[1] = ptr[2];
349
 
    to[2] = ptr[1];
350
 
    to[3] = ptr[0];
 
351
    to[0] = ptr[7];
 
352
    to[1] = ptr[6];
 
353
    to[2] = ptr[5];
 
354
    to[3] = ptr[4];
 
355
    to[4] = ptr[3];
 
356
    to[5] = ptr[2];
 
357
    to[6] = ptr[1];
 
358
    to[7] = ptr[0];
351
359
  }
352
360
}
353
361
 
359
367
void Field_timestamp::set_time()
360
368
{
361
369
  Session *session= getTable() ? getTable()->in_use : current_session;
362
 
  long tmp= (long) session->query_start();
 
370
  time_t tmp= session->query_start();
363
371
  set_notnull();
364
372
  store_timestamp(tmp);
365
373
}
379
387
    return 0;
380
388
#ifdef WORDS_BIGENDIAN
381
389
  if (getTable() && getTable()->s->db_low_byte_first)
382
 
    return sint4korr(ptr);
 
390
    return sint8korr(ptr);
383
391
#endif
384
 
  long tmp;
385
 
  longget(tmp,ptr);
 
392
  int64_t tmp;
 
393
  int64_tget(tmp, ptr);
386
394
  return tmp;
387
395
}
388
396
 
389
 
void Field_timestamp::store_timestamp(time_t timestamp)
 
397
void Field_timestamp::store_timestamp(int64_t timestamp)
390
398
{
391
399
#ifdef WORDS_BIGENDIAN
392
400
  if (getTable() && getTable()->s->db_low_byte_first)
393
401
  {
394
 
    int4store(ptr,timestamp);
 
402
    int8store(ptr, timestamp);
395
403
  }
396
404
  else
397
405
#endif
398
 
    longstore(ptr,(uint32_t) timestamp);
 
406
    int64_tstore(ptr, timestamp);
399
407
}
400
408
 
401
409
} /* namespace drizzled */