~vjsamuel/drizzle/rplugin-rabbitmq

520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
1
/* -*- mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
4
 *  Copyright (C) 2008 Sun Microsystems
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
22
#include "config.h"
214 by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing).
23
#include <drizzled/field/timestamp.h>
550 by Monty Taylor
Moved error.h into just the files that need it.
24
#include <drizzled/error.h>
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
25
#include <drizzled/tztime.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
26
#include <drizzled/table.h>
27
#include <drizzled/session.h>
907.1.8 by Jay Pipes
Final removal of timezones
28
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
29
#include <math.h>
30
1241.9.17 by Monty Taylor
Removed more bits from server_includes.
31
#include <sstream>
32
907.1.8 by Jay Pipes
Final removal of timezones
33
#include "drizzled/temporal.h"
34
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
namespace drizzled
36
{
37
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
38
/**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
39
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
40
  2038-01-01 00:00:00 UTC stored as number of seconds since Unix
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
41
  Epoch in UTC.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
42
43
  Up to one of timestamps columns in the table can be automatically
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
44
  set on row update and/or have NOW() as default value.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
45
  TABLE::timestamp_field points to Field object for such timestamp with
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
46
  auto-set-on-update. TABLE::time_stamp holds offset in record + 1 for this
47
  field, and is used by handler code which performs updates required.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
48
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
49
  Actually SQL-99 says that we should allow niladic functions (like NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
50
  as defaults for any field. Current limitations (only NOW() and only
51
  for one TIMESTAMP field) are because of restricted binary .frm format
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
52
  and should go away in the future.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
53
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
54
  Also because of this limitation of binary .frm format we use 5 different
55
  unireg_check values with TIMESTAMP field to distinguish various cases of
56
  DEFAULT or ON UPDATE values. These values are:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
57
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
58
  TIMESTAMP_OLD_FIELD - old timestamp, if there was not any fields with
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
59
    auto-set-on-update (or now() as default) in this table before, then this
60
    field has NOW() as default and is updated when row changes, else it is
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
61
    field which has 0 as default value and is not automatically updated.
62
  TIMESTAMP_DN_FIELD - field with NOW() as default but not set on update
63
    automatically (TIMESTAMP DEFAULT NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
64
  TIMESTAMP_UN_FIELD - field which is set on update automatically but has not
65
    NOW() as default (but it may has 0 or some other const timestamp as
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
66
    default) (TIMESTAMP ON UPDATE NOW()).
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
67
  TIMESTAMP_DNUN_FIELD - field which has now() as default and is auto-set on
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
68
    update. (TIMESTAMP DEFAULT NOW() ON UPDATE NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
69
  NONE - field which is not auto-set on update with some other than NOW()
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
70
    default value (TIMESTAMP DEFAULT 0).
71
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
72
  Note that TIMESTAMP_OLD_FIELDs are never created explicitly now, they are
73
  left only for preserving ability to read old tables. Such fields replaced
74
  with their newer analogs in CREATE TABLE and in SHOW CREATE TABLE. This is
75
  because we want to prefer NONE unireg_check before TIMESTAMP_OLD_FIELD for
76
  "TIMESTAMP DEFAULT 'Const'" field. (Old timestamps allowed such
77
  specification too but ignored default value for first timestamp, which of
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
78
  course is non-standard.) In most cases user won't notice any change, only
79
  exception is different behavior of old/new timestamps during ALTER TABLE.
80
 */
481 by Brian Aker
Remove all of uchar.
81
Field_timestamp::Field_timestamp(unsigned char *ptr_arg,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
82
                                 uint32_t,
83
                                 unsigned char *null_ptr_arg,
84
                                 unsigned char null_bit_arg,
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
85
                                 enum utype unireg_check_arg,
86
                                 const char *field_name_arg,
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
87
                                 TableShare *share,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
88
                                 const CHARSET_INFO * const cs)
1079.4.1 by Stewart Smith
fix length of timestamp type for metadata test (and fix its result). See jay's description at https://code.launchpad.net/~stewart-flamingspork/drizzle/bug373468/+merge/8089
89
  :Field_str(ptr_arg,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
90
             DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
91
             null_ptr_arg,
92
             null_bit_arg,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
93
             field_name_arg,
94
             cs)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
95
{
96
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
216 by Brian Aker
Remove completely ZEROFILL
97
  flags|= UNSIGNED_FLAG;
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
98
  unireg_check= unireg_check_arg;
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
99
  if (! share->getTimestampField() && unireg_check != NONE)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
100
  {
101
    /* This timestamp has auto-update */
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
102
    share->setTimestampField(this);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
103
    flags|= TIMESTAMP_FLAG;
104
    if (unireg_check != TIMESTAMP_DN_FIELD)
105
      flags|= ON_UPDATE_NOW_FLAG;
106
  }
107
}
108
109
Field_timestamp::Field_timestamp(bool maybe_null_arg,
110
                                 const char *field_name_arg,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
111
                                 const CHARSET_INFO * const cs)
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
112
  :Field_str((unsigned char*) NULL,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
113
             DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
114
             maybe_null_arg ? (unsigned char*) "": 0,
115
             0,
1119.9.14 by Jay Pipes
Style cleanups after review. Thanks Monty :)
116
             field_name_arg,
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
117
             cs)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
118
{
119
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
216 by Brian Aker
Remove completely ZEROFILL
120
  flags|= UNSIGNED_FLAG;
1119.9.12 by Jay Pipes
First phase removal of MTYP_TYPENR() macro. This removes the unireg_check argument for all Field types where it is irrelevant (everything but numeric types and timestamp.
121
  if (unireg_check != TIMESTAMP_DN_FIELD)
122
    flags|= ON_UPDATE_NOW_FLAG;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
123
}
124
125
/**
126
  Get auto-set type for TIMESTAMP field.
127
128
  Returns value indicating during which operations this TIMESTAMP field
129
  should be auto-set to current timestamp.
130
*/
131
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
132
{
133
  switch (unireg_check)
134
  {
135
  case TIMESTAMP_DN_FIELD:
136
    return TIMESTAMP_AUTO_SET_ON_INSERT;
137
  case TIMESTAMP_UN_FIELD:
138
    return TIMESTAMP_AUTO_SET_ON_UPDATE;
139
  case TIMESTAMP_OLD_FIELD:
140
    /*
141
      Although we can have several such columns in legacy tables this
142
      function should be called only for first of them (i.e. the one
143
      having auto-set property).
144
    */
1660.1.3 by Brian Aker
Encapsulate Table in field
145
    assert(getTable()->timestamp_field == this);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
146
    /* Fall-through */
147
  case TIMESTAMP_DNUN_FIELD:
148
    return TIMESTAMP_AUTO_SET_ON_BOTH;
149
  default:
150
    /*
151
      Normally this function should not be called for TIMESTAMPs without
152
      auto-set property.
153
    */
154
    assert(0);
155
    return TIMESTAMP_NO_AUTO_SET;
156
  }
157
}
158
159
int Field_timestamp::store(const char *from,
482 by Brian Aker
Remove uint.
160
                           uint32_t len,
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
161
                           const CHARSET_INFO * const )
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
162
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
163
  Timestamp temporal;
907.1.7 by Jay Pipes
Merged in remove-timezone work
164
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
165
  ASSERT_COLUMN_MARKED_FOR_WRITE;
166
907.1.7 by Jay Pipes
Merged in remove-timezone work
167
  if (! temporal.from_string(from, (size_t) len))
168
  {
169
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
170
    return 1;
171
  }
172
173
  time_t tmp;
174
  temporal.to_time_t(&tmp);
175
176
  store_timestamp(tmp);
177
  return 0;
178
}
179
180
int Field_timestamp::store(double from)
181
{
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
182
  ASSERT_COLUMN_MARKED_FOR_WRITE;
183
907.1.7 by Jay Pipes
Merged in remove-timezone work
184
  if (from < 0 || from > 99991231235959.0)
185
  {
186
    /* Convert the double to a string using stringstream */
187
    std::stringstream ss;
188
    std::string tmp;
189
    ss.precision(18); /* 18 places should be fine for error display of double input. */
190
    ss << from; ss >> tmp;
191
192
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
193
    return 2;
194
  }
195
  return Field_timestamp::store((int64_t) rint(from), false);
196
}
197
198
int Field_timestamp::store(int64_t from, bool)
199
{
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
200
  ASSERT_COLUMN_MARKED_FOR_WRITE;
201
907.1.7 by Jay Pipes
Merged in remove-timezone work
202
  /* 
203
   * Try to create a DateTime from the supplied integer.  Throw an error
204
   * if unable to create a valid DateTime.  
205
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
206
  Timestamp temporal;
907.1.7 by Jay Pipes
Merged in remove-timezone work
207
  if (! temporal.from_int64_t(from))
208
  {
209
    /* Convert the integer to a string using stringstream */
210
    std::stringstream ss;
211
    std::string tmp;
212
    ss << from; ss >> tmp;
213
214
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
215
    return 2;
216
  }
217
218
  time_t tmp;
219
  temporal.to_time_t(&tmp);
220
221
  store_timestamp(tmp);
222
  return 0;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
223
}
224
225
double Field_timestamp::val_real(void)
226
{
227
  return (double) Field_timestamp::val_int();
228
}
229
230
int64_t Field_timestamp::val_int(void)
231
{
205 by Brian Aker
uint32 -> uin32_t
232
  uint32_t temp;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
233
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
234
  ASSERT_COLUMN_MARKED_FOR_READ;
235
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
236
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
237
  if (getTable() && getTable()->s->db_low_byte_first)
907.1.8 by Jay Pipes
Final removal of timezones
238
    temp= uint4korr(ptr);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
239
  else
240
#endif
907.1.8 by Jay Pipes
Final removal of timezones
241
    longget(temp, ptr);
242
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
243
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
244
  (void) temporal.from_time_t((time_t) temp);
245
246
  /* We must convert into a "timestamp-formatted integer" ... */
247
  int64_t result;
248
  temporal.to_int64_t(&result);
249
  return result;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
250
}
251
907.1.8 by Jay Pipes
Final removal of timezones
252
String *Field_timestamp::val_str(String *val_buffer, String *)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
253
{
907.1.8 by Jay Pipes
Final removal of timezones
254
  uint32_t temp;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
255
  char *to;
1079.3.1 by Stewart Smith
Change temporal to_string routines to use snprintf instead of sprintf.
256
  int to_len= field_length + 1;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
257
1079.3.1 by Stewart Smith
Change temporal to_string routines to use snprintf instead of sprintf.
258
  val_buffer->alloc(to_len);
907.1.8 by Jay Pipes
Final removal of timezones
259
  to= (char *) val_buffer->ptr();
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
260
261
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
262
  if (getTable() && getTable()->s->db_low_byte_first)
907.1.8 by Jay Pipes
Final removal of timezones
263
    temp= uint4korr(ptr);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
264
  else
265
#endif
907.1.8 by Jay Pipes
Final removal of timezones
266
    longget(temp, ptr);
267
268
  val_buffer->set_charset(&my_charset_bin);	/* Safety */
269
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
270
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
271
  (void) temporal.from_time_t((time_t) temp);
1079.3.1 by Stewart Smith
Change temporal to_string routines to use snprintf instead of sprintf.
272
273
  int rlen;
274
  rlen= temporal.to_string(to, to_len);
275
  assert(rlen < to_len);
276
1079.3.2 by Stewart Smith
Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.
277
  val_buffer->length(rlen);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
278
  return val_buffer;
279
}
280
907.1.8 by Jay Pipes
Final removal of timezones
281
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
282
{
907.1.8 by Jay Pipes
Final removal of timezones
283
  uint32_t temp;
284
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
285
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
286
  if (getTable() && getTable()->s->db_low_byte_first)
907.1.8 by Jay Pipes
Final removal of timezones
287
    temp= uint4korr(ptr);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
288
  else
289
#endif
907.1.8 by Jay Pipes
Final removal of timezones
290
    longget(temp, ptr);
291
  
292
  memset(ltime, 0, sizeof(*ltime));
293
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
294
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
295
  (void) temporal.from_time_t((time_t) temp);
296
297
  /* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
298
299
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
300
  ltime->year= temporal.years();
301
  ltime->month= temporal.months();
302
  ltime->day= temporal.days();
303
  ltime->hour= temporal.hours();
304
  ltime->minute= temporal.minutes();
305
  ltime->second= temporal.seconds();
306
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
307
  return 0;
308
}
309
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
310
bool Field_timestamp::get_time(DRIZZLE_TIME *ltime)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
311
{
312
  return Field_timestamp::get_date(ltime,0);
313
}
314
481 by Brian Aker
Remove all of uchar.
315
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
316
{
205 by Brian Aker
uint32 -> uin32_t
317
  int32_t a,b;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
318
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
319
  if (getTable() && getTable()->s->db_low_byte_first)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
320
  {
321
    a=sint4korr(a_ptr);
322
    b=sint4korr(b_ptr);
323
  }
324
  else
325
#endif
326
  {
327
  longget(a,a_ptr);
328
  longget(b,b_ptr);
329
  }
205 by Brian Aker
uint32 -> uin32_t
330
  return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
331
}
332
333
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
334
void Field_timestamp::sort_string(unsigned char *to,uint32_t )
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
335
{
336
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
337
  if (!getTable() || !getTable()->s->db_low_byte_first)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
338
  {
339
    to[0] = ptr[0];
340
    to[1] = ptr[1];
341
    to[2] = ptr[2];
342
    to[3] = ptr[3];
343
  }
344
  else
345
#endif
346
  {
347
    to[0] = ptr[3];
348
    to[1] = ptr[2];
349
    to[2] = ptr[1];
350
    to[3] = ptr[0];
351
  }
352
}
353
354
void Field_timestamp::sql_type(String &res) const
355
{
356
  res.set_ascii(STRING_WITH_LEN("timestamp"));
357
}
358
359
void Field_timestamp::set_time()
360
{
1660.1.3 by Brian Aker
Encapsulate Table in field
361
  Session *session= getTable() ? getTable()->in_use : current_session;
520.1.22 by Brian Aker
Second pass of thd cleanup
362
  long tmp= (long) session->query_start();
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
363
  set_notnull();
364
  store_timestamp(tmp);
365
}
366
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
367
void Field_timestamp::set_default()
368
{
1660.1.3 by Brian Aker
Encapsulate Table in field
369
  if (getTable()->timestamp_field == this &&
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
370
      unireg_check != TIMESTAMP_UN_FIELD)
371
    set_time();
372
  else
373
    Field::set_default();
374
}
375
376
long Field_timestamp::get_timestamp(bool *null_value)
377
{
378
  if ((*null_value= is_null()))
379
    return 0;
380
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
381
  if (getTable() && getTable()->s->db_low_byte_first)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
382
    return sint4korr(ptr);
383
#endif
384
  long tmp;
385
  longget(tmp,ptr);
386
  return tmp;
387
}
388
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
389
void Field_timestamp::store_timestamp(time_t timestamp)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
390
{
391
#ifdef WORDS_BIGENDIAN
1660.1.3 by Brian Aker
Encapsulate Table in field
392
  if (getTable() && getTable()->s->db_low_byte_first)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
393
  {
394
    int4store(ptr,timestamp);
395
  }
396
  else
397
#endif
398
    longstore(ptr,(uint32_t) timestamp);
399
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
400
401
} /* namespace drizzled */