~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Jay Pipes
  • Date: 2009-03-01 03:08:20 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: jpipes@serialcoder-20090301030820-8kxgypvo3yexa9d1
Final removal of timezones

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/tztime.h>
26
26
#include <drizzled/table.h>
27
27
#include <drizzled/session.h>
 
28
 
 
29
#include "drizzled/temporal.h"
 
30
 
28
31
#include CMATH_H
29
32
 
30
33
#if defined(CMATH_NAMESPACE)
74
77
  course is non-standard.) In most cases user won't notice any change, only
75
78
  exception is different behavior of old/new timestamps during ALTER TABLE.
76
79
 */
77
 
 
78
80
Field_timestamp::Field_timestamp(unsigned char *ptr_arg,
79
81
                                 uint32_t ,
80
82
                                 unsigned char *null_ptr_arg, unsigned char null_bit_arg,
97
99
  }
98
100
}
99
101
 
100
 
 
101
102
Field_timestamp::Field_timestamp(bool maybe_null_arg,
102
103
                                 const char *field_name_arg,
103
104
                                 const CHARSET_INFO * const cs)
111
112
      flags|= ON_UPDATE_NOW_FLAG;
112
113
}
113
114
 
114
 
 
115
115
/**
116
116
  Get auto-set type for TIMESTAMP field.
117
117
 
214
214
int64_t Field_timestamp::val_int(void)
215
215
{
216
216
  uint32_t temp;
217
 
  DRIZZLE_TIME time_tmp;
218
 
  Session  *session= table ? table->in_use : current_session;
219
217
 
220
218
#ifdef WORDS_BIGENDIAN
221
219
  if (table && table->s->db_low_byte_first)
222
 
    temp=uint4korr(ptr);
 
220
    temp= uint4korr(ptr);
223
221
  else
224
222
#endif
225
 
    longget(temp,ptr);
226
 
 
227
 
  if (temp == 0L)                               // No time
228
 
    return(0);                                  /* purecov: inspected */
229
 
 
230
 
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (time_t)temp);
231
 
 
232
 
  return time_tmp.year * INT64_C(10000000000) +
233
 
         time_tmp.month * INT64_C(100000000) +
234
 
         time_tmp.day * 1000000 + time_tmp.hour * 10000 +
235
 
         time_tmp.minute * 100 + time_tmp.second;
 
223
    longget(temp, ptr);
 
224
 
 
225
  drizzled::Timestamp temporal;
 
226
  (void) temporal.from_time_t((time_t) temp);
 
227
 
 
228
  /* We must convert into a "timestamp-formatted integer" ... */
 
229
  int64_t result;
 
230
  temporal.to_int64_t(&result);
 
231
  return result;
236
232
}
237
233
 
238
 
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
 
234
String *Field_timestamp::val_str(String *val_buffer, String *)
239
235
{
240
 
  uint32_t temp, temp2;
241
 
  DRIZZLE_TIME time_tmp;
242
 
  Session *session= table ? table->in_use : current_session;
 
236
  uint32_t temp;
243
237
  char *to;
244
238
 
245
 
  val_buffer->alloc(field_length+1);
246
 
  to= (char*) val_buffer->ptr();
247
 
  val_buffer->length(field_length);
 
239
  val_buffer->alloc(field_length + 1);
 
240
  to= (char *) val_buffer->ptr();
248
241
 
249
242
#ifdef WORDS_BIGENDIAN
250
243
  if (table && table->s->db_low_byte_first)
251
 
    temp=uint4korr(ptr);
 
244
    temp= uint4korr(ptr);
252
245
  else
253
246
#endif
254
 
    longget(temp,ptr);
255
 
 
256
 
  if (temp == 0L)
257
 
  {                                   /* Zero time is "000000" */
258
 
    val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin);
259
 
    return val_ptr;
260
 
  }
261
 
  val_buffer->set_charset(&my_charset_bin);     // Safety
262
 
 
263
 
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(time_t)temp);
264
 
 
265
 
  temp= time_tmp.year % 100;
266
 
  if (temp < YY_PART_YEAR - 1)
267
 
  {
268
 
    *to++= '2';
269
 
    *to++= '0';
270
 
  }
271
 
  else
272
 
  {
273
 
    *to++= '1';
274
 
    *to++= '9';
275
 
  }
276
 
  temp2=temp/10; temp=temp-temp2*10;
277
 
  *to++= (char) ('0'+(char) (temp2));
278
 
  *to++= (char) ('0'+(char) (temp));
279
 
  *to++= '-';
280
 
  temp=time_tmp.month;
281
 
  temp2=temp/10; temp=temp-temp2*10;
282
 
  *to++= (char) ('0'+(char) (temp2));
283
 
  *to++= (char) ('0'+(char) (temp));
284
 
  *to++= '-';
285
 
  temp=time_tmp.day;
286
 
  temp2=temp/10; temp=temp-temp2*10;
287
 
  *to++= (char) ('0'+(char) (temp2));
288
 
  *to++= (char) ('0'+(char) (temp));
289
 
  *to++= ' ';
290
 
  temp=time_tmp.hour;
291
 
  temp2=temp/10; temp=temp-temp2*10;
292
 
  *to++= (char) ('0'+(char) (temp2));
293
 
  *to++= (char) ('0'+(char) (temp));
294
 
  *to++= ':';
295
 
  temp=time_tmp.minute;
296
 
  temp2=temp/10; temp=temp-temp2*10;
297
 
  *to++= (char) ('0'+(char) (temp2));
298
 
  *to++= (char) ('0'+(char) (temp));
299
 
  *to++= ':';
300
 
  temp=time_tmp.second;
301
 
  temp2=temp/10; temp=temp-temp2*10;
302
 
  *to++= (char) ('0'+(char) (temp2));
303
 
  *to++= (char) ('0'+(char) (temp));
304
 
  *to= 0;
 
247
    longget(temp, ptr);
 
248
 
 
249
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
 
250
 
 
251
  drizzled::Timestamp temporal;
 
252
  (void) temporal.from_time_t((time_t) temp);
 
253
  size_t to_len;
 
254
 
 
255
  temporal.to_string(to, &to_len);
 
256
  val_buffer->length((uint32_t) to_len);
305
257
  return val_buffer;
306
258
}
307
259
 
308
 
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
 
260
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t)
309
261
{
310
 
  long temp;
311
 
  Session *session= table ? table->in_use : current_session;
 
262
  uint32_t temp;
 
263
 
312
264
#ifdef WORDS_BIGENDIAN
313
265
  if (table && table->s->db_low_byte_first)
314
 
    temp=uint4korr(ptr);
 
266
    temp= uint4korr(ptr);
315
267
  else
316
268
#endif
317
 
    longget(temp,ptr);
318
 
  if (temp == 0L)
319
 
  {                                   /* Zero time is "000000" */
320
 
    if (fuzzydate & TIME_NO_ZERO_DATE)
321
 
      return 1;
322
 
    memset(ltime, 0, sizeof(*ltime));
323
 
  }
324
 
  else
325
 
  {
326
 
    session->variables.time_zone->gmt_sec_to_TIME(ltime, (time_t)temp);
327
 
  }
 
269
    longget(temp, ptr);
 
270
  
 
271
  memset(ltime, 0, sizeof(*ltime));
 
272
 
 
273
  drizzled::Timestamp temporal;
 
274
  (void) temporal.from_time_t((time_t) temp);
 
275
 
 
276
  /* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
 
277
 
 
278
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
279
  ltime->year= temporal.years();
 
280
  ltime->month= temporal.months();
 
281
  ltime->day= temporal.days();
 
282
  ltime->hour= temporal.hours();
 
283
  ltime->minute= temporal.minutes();
 
284
  ltime->second= temporal.seconds();
 
285
 
328
286
  return 0;
329
287
}
330
288
 
372
330
  }
373
331
}
374
332
 
375
 
 
376
333
void Field_timestamp::sql_type(String &res) const
377
334
{
378
335
  res.set_ascii(STRING_WITH_LEN("timestamp"));
379
336
}
380
337
 
381
 
 
382
338
void Field_timestamp::set_time()
383
339
{
384
340
  Session *session= table ? table->in_use : current_session;
387
343
  store_timestamp(tmp);
388
344
}
389
345
 
390
 
 
391
346
void Field_timestamp::set_default()
392
347
{
393
348
  if (table->timestamp_field == this &&
410
365
  return tmp;
411
366
}
412
367
 
413
 
 
414
368
void Field_timestamp::store_timestamp(time_t timestamp)
415
369
{
416
370
#ifdef WORDS_BIGENDIAN
422
376
#endif
423
377
    longstore(ptr,(uint32_t) timestamp);
424
378
}
425