~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Brian Aker
  • Date: 2009-02-10 00:14:40 UTC
  • Revision ID: brian@tangent.org-20090210001440-qjg8eofh3h93064b
Adding Multi-threaded Scheduler into the system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
21
 
23
 
#include <boost/lexical_cast.hpp>
24
 
#include <drizzled/field/epoch.h>
 
22
#include <drizzled/server_includes.h>
 
23
#include <drizzled/field/timestamp.h>
25
24
#include <drizzled/error.h>
26
25
#include <drizzled/tztime.h>
27
26
#include <drizzled/table.h>
28
27
#include <drizzled/session.h>
29
 
#include <drizzled/current_session.h>
30
 
 
31
 
#include <math.h>
32
 
 
33
 
#include <sstream>
34
 
 
35
 
#include <drizzled/temporal.h>
36
 
 
37
 
namespace drizzled
38
 
{
39
 
 
40
 
namespace field
41
 
{
 
28
#include CMATH_H
 
29
 
 
30
#if defined(CMATH_NAMESPACE)
 
31
using namespace CMATH_NAMESPACE;
 
32
#endif
42
33
 
43
34
/**
44
35
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
83
74
  course is non-standard.) In most cases user won't notice any change, only
84
75
  exception is different behavior of old/new timestamps during ALTER TABLE.
85
76
 */
86
 
  Epoch::Epoch(unsigned char *ptr_arg,
87
 
               unsigned char *null_ptr_arg,
88
 
               unsigned char null_bit_arg,
89
 
               enum utype unireg_check_arg,
90
 
               const char *field_name_arg,
91
 
               drizzled::TableShare *share) :
92
 
  Field_str(ptr_arg,
93
 
            MicroTimestamp::MAX_STRING_LENGTH - 1, /* no \0 */
94
 
            null_ptr_arg,
95
 
            null_bit_arg,
96
 
            field_name_arg,
97
 
            &my_charset_bin)
 
77
 
 
78
Field_timestamp::Field_timestamp(unsigned char *ptr_arg,
 
79
                                 uint32_t ,
 
80
                                 unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
81
                                 enum utype unireg_check_arg,
 
82
                                 const char *field_name_arg,
 
83
                                 TABLE_SHARE *share,
 
84
                                 const CHARSET_INFO * const cs)
 
85
  :Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
 
86
             unireg_check_arg, field_name_arg, cs)
98
87
{
99
 
  unireg_check= unireg_check_arg;
100
 
  if (! share->getTimestampField() && unireg_check != NONE)
 
88
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
 
89
  flags|= UNSIGNED_FLAG;
 
90
  if (!share->timestamp_field && unireg_check != NONE)
101
91
  {
102
92
    /* This timestamp has auto-update */
103
 
    share->setTimestampField(this);
104
 
    flags|= FUNCTION_DEFAULT_FLAG;
 
93
    share->timestamp_field= this;
 
94
    flags|= TIMESTAMP_FLAG;
105
95
    if (unireg_check != TIMESTAMP_DN_FIELD)
106
96
      flags|= ON_UPDATE_NOW_FLAG;
107
97
  }
108
98
}
109
99
 
110
 
Epoch::Epoch(bool maybe_null_arg,
111
 
             const char *field_name_arg) :
112
 
  Field_str((unsigned char*) NULL,
113
 
            MicroTimestamp::MAX_STRING_LENGTH - 1, /* no \0 */
114
 
            maybe_null_arg ? (unsigned char*) "": 0,
115
 
            0,
116
 
            field_name_arg,
117
 
            &my_charset_bin)
 
100
 
 
101
Field_timestamp::Field_timestamp(bool maybe_null_arg,
 
102
                                 const char *field_name_arg,
 
103
                                 const CHARSET_INFO * const cs)
 
104
  :Field_str((unsigned char*) 0, MAX_DATETIME_WIDTH,
 
105
             maybe_null_arg ? (unsigned char*) "": 0, 0,
 
106
             NONE, field_name_arg, cs)
118
107
{
119
 
  if (unireg_check != TIMESTAMP_DN_FIELD)
120
 
    flags|= ON_UPDATE_NOW_FLAG;
 
108
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
 
109
  flags|= UNSIGNED_FLAG;
 
110
    if (unireg_check != TIMESTAMP_DN_FIELD)
 
111
      flags|= ON_UPDATE_NOW_FLAG;
121
112
}
122
113
 
 
114
 
123
115
/**
124
116
  Get auto-set type for TIMESTAMP field.
125
117
 
126
118
  Returns value indicating during which operations this TIMESTAMP field
127
119
  should be auto-set to current timestamp.
128
120
*/
129
 
timestamp_auto_set_type Epoch::get_auto_set_type() const
 
121
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
130
122
{
131
123
  switch (unireg_check)
132
124
  {
140
132
      function should be called only for first of them (i.e. the one
141
133
      having auto-set property).
142
134
    */
143
 
    assert(getTable()->timestamp_field == this);
 
135
    assert(table->timestamp_field == this);
144
136
    /* Fall-through */
145
137
  case TIMESTAMP_DNUN_FIELD:
146
138
    return TIMESTAMP_AUTO_SET_ON_BOTH;
154
146
  }
155
147
}
156
148
 
157
 
int Epoch::store(const char *from,
158
 
                 uint32_t len,
159
 
                 const CHARSET_INFO * const )
160
 
{
161
 
  Timestamp temporal;
162
 
 
163
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
164
 
 
165
 
  if (not temporal.from_string(from, (size_t) len))
166
 
  {
167
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
168
 
    return 1;
169
 
  }
170
 
 
171
 
  time_t tmp;
172
 
  temporal.to_time_t(tmp);
173
 
 
174
 
  uint64_t time_tmp= tmp;
175
 
  pack_num(time_tmp);
176
 
  return 0;
177
 
}
178
 
 
179
 
int Epoch::store(double from)
180
 
{
181
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
182
 
 
183
 
  uint64_t from_tmp= (uint64_t)from;
184
 
 
185
 
  Timestamp temporal;
186
 
  if (not temporal.from_int64_t(from_tmp))
187
 
  {
188
 
    /* Convert the integer to a string using boost::lexical_cast */
189
 
    std::string tmp(boost::lexical_cast<std::string>(from));
190
 
 
191
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
192
 
    return 2;
193
 
  }
194
 
 
195
 
  time_t tmp;
196
 
  temporal.to_time_t(tmp);
197
 
 
198
 
  uint64_t tmp_micro= tmp;
199
 
  pack_num(tmp_micro);
200
 
 
201
 
  return 0;
202
 
}
203
 
 
204
 
int Epoch::store_decimal(const type::Decimal *value)
205
 
{
206
 
  double tmp;
207
 
  value->convert(tmp);
208
 
 
209
 
  return store(tmp);
210
 
}
211
 
 
212
 
int Epoch::store(int64_t from, bool)
213
 
{
214
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
215
 
 
216
 
  /* 
217
 
   * Try to create a DateTime from the supplied integer.  Throw an error
218
 
   * if unable to create a valid DateTime.  
219
 
   */
220
 
  Timestamp temporal;
221
 
  if (not temporal.from_int64_t(from))
222
 
  {
223
 
    /* Convert the integer to a string using boost::lexical_cast */
224
 
    std::string tmp(boost::lexical_cast<std::string>(from));
225
 
 
226
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
227
 
    return 2;
228
 
  }
229
 
 
230
 
  time_t tmp;
231
 
  temporal.to_time_t(tmp);
232
 
 
233
 
  uint64_t tmp64= tmp;
234
 
  pack_num(tmp64);
235
 
 
236
 
  return 0;
237
 
}
238
 
 
239
 
double Epoch::val_real(void) const
240
 
{
241
 
  return (double) Epoch::val_int();
242
 
}
243
 
 
244
 
int64_t Epoch::val_int(void) const
245
 
{
246
 
  uint64_t temp;
247
 
 
248
 
  ASSERT_COLUMN_MARKED_FOR_READ;
249
 
 
250
 
  unpack_num(temp);
251
 
 
252
 
  Timestamp temporal;
253
 
  (void) temporal.from_time_t((time_t) temp);
254
 
 
255
 
  /* We must convert into a "timestamp-formatted integer" ... */
256
 
  int64_t result;
257
 
  temporal.to_int64_t(&result);
258
 
  return result;
259
 
}
260
 
 
261
 
String *Epoch::val_str(String *val_buffer, String *) const
262
 
{
263
 
  uint64_t temp= 0;
 
149
 
 
150
int Field_timestamp::store(const char *from,
 
151
                           uint32_t len,
 
152
                           const CHARSET_INFO * const )
 
153
{
 
154
  DRIZZLE_TIME l_time;
 
155
  time_t tmp= 0;
 
156
  int error;
 
157
  bool have_smth_to_conv;
 
158
  bool in_dst_time_gap;
 
159
  Session *session= table ? table->in_use : current_session;
 
160
 
 
161
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
 
162
  have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) >
 
163
                      DRIZZLE_TIMESTAMP_ERROR);
 
164
 
 
165
  if (error || !have_smth_to_conv)
 
166
  {
 
167
    error= 1;
 
168
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
 
169
                         from, len, DRIZZLE_TIMESTAMP_DATETIME, 1);
 
170
  }
 
171
 
 
172
  /* Only convert a correct date (not a zero date) */
 
173
  if (have_smth_to_conv && l_time.month)
 
174
  {
 
175
    if (!(tmp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap)))
 
176
    {
 
177
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
178
                           ER_WARN_DATA_OUT_OF_RANGE,
 
179
                           from, len, DRIZZLE_TIMESTAMP_DATETIME, !error);
 
180
      error= 1;
 
181
    }
 
182
    else if (in_dst_time_gap)
 
183
    {
 
184
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
185
                           ER_WARN_INVALID_TIMESTAMP,
 
186
                           from, len, DRIZZLE_TIMESTAMP_DATETIME, !error);
 
187
      error= 1;
 
188
    }
 
189
  }
 
190
  store_timestamp(tmp);
 
191
  return error;
 
192
}
 
193
 
 
194
 
 
195
int Field_timestamp::store(double nr)
 
196
{
 
197
  int error= 0;
 
198
  if (nr < 0 || nr > 99991231235959.0)
 
199
  {
 
200
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
201
                         ER_WARN_DATA_OUT_OF_RANGE,
 
202
                         nr, DRIZZLE_TIMESTAMP_DATETIME);
 
203
    nr= 0;                                      // Avoid overflow on buff
 
204
    error= 1;
 
205
  }
 
206
  error|= Field_timestamp::store((int64_t) rint(nr), false);
 
207
  return error;
 
208
}
 
209
 
 
210
 
 
211
int Field_timestamp::store(int64_t nr,
 
212
                           bool )
 
213
{
 
214
  DRIZZLE_TIME l_time;
 
215
  time_t timestamp= 0;
 
216
  int error;
 
217
  bool in_dst_time_gap;
 
218
  Session *session= table ? table->in_use : current_session;
 
219
 
 
220
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
 
221
  int64_t tmp= number_to_datetime(nr, &l_time, (session->variables.sql_mode &
 
222
                                                 MODE_NO_ZERO_DATE), &error);
 
223
  if (tmp == INT64_C(-1))
 
224
  {
 
225
    error= 2;
 
226
  }
 
227
 
 
228
  if (!error && tmp)
 
229
  {
 
230
    if (!(timestamp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap)))
 
231
    {
 
232
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
233
                           ER_WARN_DATA_OUT_OF_RANGE,
 
234
                           nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
 
235
      error= 1;
 
236
    }
 
237
    if (in_dst_time_gap)
 
238
    {
 
239
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
240
                           ER_WARN_INVALID_TIMESTAMP,
 
241
                           nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
 
242
      error= 1;
 
243
    }
 
244
  } else if (error)
 
245
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
246
                         ER_WARN_DATA_TRUNCATED,
 
247
                         nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
 
248
 
 
249
  store_timestamp(timestamp);
 
250
  return error;
 
251
}
 
252
 
 
253
double Field_timestamp::val_real(void)
 
254
{
 
255
  return (double) Field_timestamp::val_int();
 
256
}
 
257
 
 
258
int64_t Field_timestamp::val_int(void)
 
259
{
 
260
  uint32_t temp;
 
261
  DRIZZLE_TIME time_tmp;
 
262
  Session  *session= table ? table->in_use : current_session;
 
263
 
 
264
#ifdef WORDS_BIGENDIAN
 
265
  if (table && table->s->db_low_byte_first)
 
266
    temp=uint4korr(ptr);
 
267
  else
 
268
#endif
 
269
    longget(temp,ptr);
 
270
 
 
271
  if (temp == 0L)                               // No time
 
272
    return(0);                                  /* purecov: inspected */
 
273
 
 
274
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (time_t)temp);
 
275
 
 
276
  return time_tmp.year * INT64_C(10000000000) +
 
277
         time_tmp.month * INT64_C(100000000) +
 
278
         time_tmp.day * 1000000 + time_tmp.hour * 10000 +
 
279
         time_tmp.minute * 100 + time_tmp.second;
 
280
}
 
281
 
 
282
 
 
283
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
 
284
{
 
285
  uint32_t temp, temp2;
 
286
  DRIZZLE_TIME time_tmp;
 
287
  Session *session= table ? table->in_use : current_session;
264
288
  char *to;
265
 
  int to_len= field_length + 1;
266
 
 
267
 
  val_buffer->alloc(to_len);
268
 
  to= (char *) val_buffer->ptr();
269
 
 
270
 
  unpack_num(temp);
271
 
 
272
 
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
273
 
 
274
 
  Timestamp temporal;
275
 
  (void) temporal.from_time_t((time_t) temp);
276
 
 
277
 
  int rlen;
278
 
  rlen= temporal.to_string(to, to_len);
279
 
  assert(rlen < to_len);
280
 
 
281
 
  val_buffer->length(rlen);
 
289
 
 
290
  val_buffer->alloc(field_length+1);
 
291
  to= (char*) val_buffer->ptr();
 
292
  val_buffer->length(field_length);
 
293
 
 
294
#ifdef WORDS_BIGENDIAN
 
295
  if (table && table->s->db_low_byte_first)
 
296
    temp=uint4korr(ptr);
 
297
  else
 
298
#endif
 
299
    longget(temp,ptr);
 
300
 
 
301
  if (temp == 0L)
 
302
  {                                   /* Zero time is "000000" */
 
303
    val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin);
 
304
    return val_ptr;
 
305
  }
 
306
  val_buffer->set_charset(&my_charset_bin);     // Safety
 
307
 
 
308
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(time_t)temp);
 
309
 
 
310
  temp= time_tmp.year % 100;
 
311
  if (temp < YY_PART_YEAR - 1)
 
312
  {
 
313
    *to++= '2';
 
314
    *to++= '0';
 
315
  }
 
316
  else
 
317
  {
 
318
    *to++= '1';
 
319
    *to++= '9';
 
320
  }
 
321
  temp2=temp/10; temp=temp-temp2*10;
 
322
  *to++= (char) ('0'+(char) (temp2));
 
323
  *to++= (char) ('0'+(char) (temp));
 
324
  *to++= '-';
 
325
  temp=time_tmp.month;
 
326
  temp2=temp/10; temp=temp-temp2*10;
 
327
  *to++= (char) ('0'+(char) (temp2));
 
328
  *to++= (char) ('0'+(char) (temp));
 
329
  *to++= '-';
 
330
  temp=time_tmp.day;
 
331
  temp2=temp/10; temp=temp-temp2*10;
 
332
  *to++= (char) ('0'+(char) (temp2));
 
333
  *to++= (char) ('0'+(char) (temp));
 
334
  *to++= ' ';
 
335
  temp=time_tmp.hour;
 
336
  temp2=temp/10; temp=temp-temp2*10;
 
337
  *to++= (char) ('0'+(char) (temp2));
 
338
  *to++= (char) ('0'+(char) (temp));
 
339
  *to++= ':';
 
340
  temp=time_tmp.minute;
 
341
  temp2=temp/10; temp=temp-temp2*10;
 
342
  *to++= (char) ('0'+(char) (temp2));
 
343
  *to++= (char) ('0'+(char) (temp));
 
344
  *to++= ':';
 
345
  temp=time_tmp.second;
 
346
  temp2=temp/10; temp=temp-temp2*10;
 
347
  *to++= (char) ('0'+(char) (temp2));
 
348
  *to++= (char) ('0'+(char) (temp));
 
349
  *to= 0;
282
350
  return val_buffer;
283
351
}
284
352
 
285
 
bool Epoch::get_date(type::Time &ltime, uint32_t) const
 
353
 
 
354
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
286
355
{
287
 
  uint64_t temp;
288
 
  type::Time::epoch_t time_temp;
289
 
 
290
 
  unpack_num(temp);
291
 
  time_temp= temp;
292
 
  
293
 
  ltime.reset();
294
 
 
295
 
  ltime.store(time_temp);
296
 
 
 
356
  long temp;
 
357
  Session *session= table ? table->in_use : current_session;
 
358
#ifdef WORDS_BIGENDIAN
 
359
  if (table && table->s->db_low_byte_first)
 
360
    temp=uint4korr(ptr);
 
361
  else
 
362
#endif
 
363
    longget(temp,ptr);
 
364
  if (temp == 0L)
 
365
  {                                   /* Zero time is "000000" */
 
366
    if (fuzzydate & TIME_NO_ZERO_DATE)
 
367
      return 1;
 
368
    memset(ltime, 0, sizeof(*ltime));
 
369
  }
 
370
  else
 
371
  {
 
372
    session->variables.time_zone->gmt_sec_to_TIME(ltime, (time_t)temp);
 
373
  }
297
374
  return 0;
298
375
}
299
376
 
300
 
bool Epoch::get_time(type::Time &ltime) const
301
 
{
302
 
  return Epoch::get_date(ltime, 0);
303
 
}
304
 
 
305
 
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
306
 
{
307
 
  uint64_t a,b;
308
 
 
309
 
  unpack_num(a, a_ptr);
310
 
  unpack_num(b, b_ptr);
311
 
 
312
 
  return (a < b) ? -1 : (a > b) ? 1 : 0;
313
 
}
314
 
 
315
 
 
316
 
void Epoch::sort_string(unsigned char *to,uint32_t )
317
 
{
318
 
#ifdef WORDS_BIGENDIAN
319
 
  if (!getTable() || !getTable()->getShare()->db_low_byte_first)
 
377
bool Field_timestamp::get_time(DRIZZLE_TIME *ltime)
 
378
{
 
379
  return Field_timestamp::get_date(ltime,0);
 
380
}
 
381
 
 
382
 
 
383
bool Field_timestamp::send_binary(Protocol *protocol)
 
384
{
 
385
  DRIZZLE_TIME tm;
 
386
  Field_timestamp::get_date(&tm, 0);
 
387
  return protocol->store(&tm);
 
388
}
 
389
 
 
390
 
 
391
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
 
392
{
 
393
  int32_t a,b;
 
394
#ifdef WORDS_BIGENDIAN
 
395
  if (table && table->s->db_low_byte_first)
 
396
  {
 
397
    a=sint4korr(a_ptr);
 
398
    b=sint4korr(b_ptr);
 
399
  }
 
400
  else
 
401
#endif
 
402
  {
 
403
  longget(a,a_ptr);
 
404
  longget(b,b_ptr);
 
405
  }
 
406
  return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
 
407
}
 
408
 
 
409
 
 
410
void Field_timestamp::sort_string(unsigned char *to,uint32_t )
 
411
{
 
412
#ifdef WORDS_BIGENDIAN
 
413
  if (!table || !table->s->db_low_byte_first)
320
414
  {
321
415
    to[0] = ptr[0];
322
416
    to[1] = ptr[1];
323
417
    to[2] = ptr[2];
324
418
    to[3] = ptr[3];
325
 
    to[4] = ptr[4];
326
 
    to[5] = ptr[5];
327
 
    to[6] = ptr[6];
328
 
    to[7] = ptr[7];
329
419
  }
330
420
  else
331
421
#endif
332
422
  {
333
 
    to[0] = ptr[7];
334
 
    to[1] = ptr[6];
335
 
    to[2] = ptr[5];
336
 
    to[3] = ptr[4];
337
 
    to[4] = ptr[3];
338
 
    to[5] = ptr[2];
339
 
    to[6] = ptr[1];
340
 
    to[7] = ptr[0];
 
423
    to[0] = ptr[3];
 
424
    to[1] = ptr[2];
 
425
    to[2] = ptr[1];
 
426
    to[3] = ptr[0];
341
427
  }
342
428
}
343
429
 
344
 
void Epoch::sql_type(String &res) const
 
430
 
 
431
void Field_timestamp::sql_type(String &res) const
345
432
{
346
433
  res.set_ascii(STRING_WITH_LEN("timestamp"));
347
434
}
348
435
 
349
 
void Epoch::set_time()
 
436
 
 
437
void Field_timestamp::set_time()
350
438
{
351
 
  Session *session= getTable() ? getTable()->in_use : current_session;
352
 
  time_t tmp= session->getCurrentTimestampEpoch();
353
 
 
 
439
  Session *session= table ? table->in_use : current_session;
 
440
  long tmp= (long) session->query_start();
354
441
  set_notnull();
355
 
  pack_num(static_cast<uint32_t>(tmp));
 
442
  store_timestamp(tmp);
356
443
}
357
444
 
358
 
void Epoch::set_default()
 
445
 
 
446
void Field_timestamp::set_default()
359
447
{
360
 
  if (getTable()->timestamp_field == this &&
 
448
  if (table->timestamp_field == this &&
361
449
      unireg_check != TIMESTAMP_UN_FIELD)
362
 
  {
363
450
    set_time();
364
 
  }
365
451
  else
366
 
  {
367
452
    Field::set_default();
368
 
  }
369
453
}
370
454
 
371
 
long Epoch::get_timestamp(bool *null_value) const
 
455
long Field_timestamp::get_timestamp(bool *null_value)
372
456
{
373
457
  if ((*null_value= is_null()))
374
458
    return 0;
375
 
 
376
 
  uint64_t tmp;
377
 
  return unpack_num(tmp);
 
459
#ifdef WORDS_BIGENDIAN
 
460
  if (table && table->s->db_low_byte_first)
 
461
    return sint4korr(ptr);
 
462
#endif
 
463
  long tmp;
 
464
  longget(tmp,ptr);
 
465
  return tmp;
378
466
}
379
467
 
380
 
size_t Epoch::max_string_length()
 
468
 
 
469
void Field_timestamp::store_timestamp(time_t timestamp)
381
470
{
382
 
  return sizeof(uint64_t);
 
471
#ifdef WORDS_BIGENDIAN
 
472
  if (table && table->s->db_low_byte_first)
 
473
  {
 
474
    int4store(ptr,timestamp);
 
475
  }
 
476
  else
 
477
#endif
 
478
    longstore(ptr,(uint32_t) timestamp);
383
479
}
384
480
 
385
 
} /* namespace field */
386
 
} /* namespace drizzled */