~drizzle-trunk/drizzle/development

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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
21
#include "config.h"
1775.5.1 by earney
modified files containing stringstream to use boost:lexical_cast instead as
22
#include <boost/lexical_cast.hpp>
1999.4.9 by Brian Aker
Created EPOCH
23
#include <drizzled/field/epoch.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
1999.4.9 by Brian Aker
Created EPOCH
38
namespace field
39
{
40
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
41
/**
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
42
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
43
  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/
44
  Epoch in UTC.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
45
46
  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/
47
  set on row update and/or have NOW() as default value.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
48
  TABLE::timestamp_field points to Field object for such timestamp with
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
49
  auto-set-on-update. TABLE::time_stamp holds offset in record + 1 for this
50
  field, and is used by handler code which performs updates required.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
51
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
52
  Actually SQL-99 says that we should allow niladic functions (like NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
53
  as defaults for any field. Current limitations (only NOW() and only
54
  for one TIMESTAMP field) are because of restricted binary .frm format
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
55
  and should go away in the future.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
56
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
57
  Also because of this limitation of binary .frm format we use 5 different
58
  unireg_check values with TIMESTAMP field to distinguish various cases of
59
  DEFAULT or ON UPDATE values. These values are:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
60
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
61
  TIMESTAMP_OLD_FIELD - old timestamp, if there was not any fields with
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
62
    auto-set-on-update (or now() as default) in this table before, then this
63
    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/
64
    field which has 0 as default value and is not automatically updated.
65
  TIMESTAMP_DN_FIELD - field with NOW() as default but not set on update
66
    automatically (TIMESTAMP DEFAULT NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
67
  TIMESTAMP_UN_FIELD - field which is set on update automatically but has not
68
    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/
69
    default) (TIMESTAMP ON UPDATE NOW()).
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
70
  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/
71
    update. (TIMESTAMP DEFAULT NOW() ON UPDATE NOW())
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
72
  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/
73
    default value (TIMESTAMP DEFAULT 0).
74
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
75
  Note that TIMESTAMP_OLD_FIELDs are never created explicitly now, they are
76
  left only for preserving ability to read old tables. Such fields replaced
77
  with their newer analogs in CREATE TABLE and in SHOW CREATE TABLE. This is
78
  because we want to prefer NONE unireg_check before TIMESTAMP_OLD_FIELD for
79
  "TIMESTAMP DEFAULT 'Const'" field. (Old timestamps allowed such
80
  specification too but ignored default value for first timestamp, which of
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
81
  course is non-standard.) In most cases user won't notice any change, only
82
  exception is different behavior of old/new timestamps during ALTER TABLE.
83
 */
1999.4.9 by Brian Aker
Created EPOCH
84
  Epoch::Epoch(unsigned char *ptr_arg,
85
               uint32_t,
86
               unsigned char *null_ptr_arg,
87
               unsigned char null_bit_arg,
88
               enum utype unireg_check_arg,
89
               const char *field_name_arg,
90
               drizzled::TableShare *share,
91
               const drizzled::CHARSET_INFO * const cs) :
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
92
  Field_str(ptr_arg,
93
            DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
94
            null_ptr_arg,
95
            null_bit_arg,
96
            field_name_arg,
97
            cs)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
98
{
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.
99
  unireg_check= unireg_check_arg;
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
100
  if (! share->getTimestampField() && unireg_check != NONE)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
101
  {
102
    /* This timestamp has auto-update */
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
103
    share->setTimestampField(this);
1976.6.1 by Brian Aker
This is a fix for bug lp:686197
104
    flags|= FUNCTION_DEFAULT_FLAG;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
105
    if (unireg_check != TIMESTAMP_DN_FIELD)
106
      flags|= ON_UPDATE_NOW_FLAG;
107
  }
108
}
109
1999.4.9 by Brian Aker
Created EPOCH
110
Epoch::Epoch(bool maybe_null_arg,
111
             const char *field_name_arg,
112
             const CHARSET_INFO * const cs) :
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
113
  Field_str((unsigned char*) NULL,
114
            DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
115
            maybe_null_arg ? (unsigned char*) "": 0,
116
            0,
117
            field_name_arg,
118
            cs)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
119
{
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.
120
  if (unireg_check != TIMESTAMP_DN_FIELD)
121
    flags|= ON_UPDATE_NOW_FLAG;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
122
}
123
124
/**
125
  Get auto-set type for TIMESTAMP field.
126
127
  Returns value indicating during which operations this TIMESTAMP field
128
  should be auto-set to current timestamp.
129
*/
1999.4.9 by Brian Aker
Created EPOCH
130
timestamp_auto_set_type Epoch::get_auto_set_type() const
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
131
{
132
  switch (unireg_check)
133
  {
134
  case TIMESTAMP_DN_FIELD:
135
    return TIMESTAMP_AUTO_SET_ON_INSERT;
136
  case TIMESTAMP_UN_FIELD:
137
    return TIMESTAMP_AUTO_SET_ON_UPDATE;
138
  case TIMESTAMP_OLD_FIELD:
139
    /*
140
      Although we can have several such columns in legacy tables this
141
      function should be called only for first of them (i.e. the one
142
      having auto-set property).
143
    */
1660.1.3 by Brian Aker
Encapsulate Table in field
144
    assert(getTable()->timestamp_field == this);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
145
    /* Fall-through */
146
  case TIMESTAMP_DNUN_FIELD:
147
    return TIMESTAMP_AUTO_SET_ON_BOTH;
148
  default:
149
    /*
150
      Normally this function should not be called for TIMESTAMPs without
151
      auto-set property.
152
    */
153
    assert(0);
154
    return TIMESTAMP_NO_AUTO_SET;
155
  }
156
}
157
1999.4.9 by Brian Aker
Created EPOCH
158
int Epoch::store(const char *from,
2016.1.7 by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to
159
                 uint32_t len,
160
                 const CHARSET_INFO * const )
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
161
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
162
  Timestamp temporal;
907.1.7 by Jay Pipes
Merged in remove-timezone work
163
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
164
  ASSERT_COLUMN_MARKED_FOR_WRITE;
165
1999.4.4 by Brian Aker
First pass through on timestamp.
166
  if (not temporal.from_string(from, (size_t) len))
907.1.7 by Jay Pipes
Merged in remove-timezone work
167
  {
168
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
169
    return 1;
170
  }
171
2016.1.7 by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to
172
  time_t tmp;
173
  temporal.to_time_t(tmp);
907.1.7 by Jay Pipes
Merged in remove-timezone work
174
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
175
  pack_num(tmp);
907.1.7 by Jay Pipes
Merged in remove-timezone work
176
  return 0;
177
}
178
1999.4.9 by Brian Aker
Created EPOCH
179
int Epoch::store(double from)
907.1.7 by Jay Pipes
Merged in remove-timezone work
180
{
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
181
  ASSERT_COLUMN_MARKED_FOR_WRITE;
182
907.1.7 by Jay Pipes
Merged in remove-timezone work
183
  if (from < 0 || from > 99991231235959.0)
184
  {
185
    /* Convert the double to a string using stringstream */
1775.5.2 by earney
removed old commented out statements and uncommmeted out first occurance of stringstream in date.cc since it sets the precision.
186
    std::stringstream ss;
187
    std::string tmp;
188
    ss.precision(18); /* 18 places should be fine for error display of double input. */
189
    ss << from; 
190
    ss >> tmp;
907.1.7 by Jay Pipes
Merged in remove-timezone work
191
192
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
193
    return 2;
194
  }
1999.4.9 by Brian Aker
Created EPOCH
195
  return Epoch::store((int64_t) rint(from), false);
907.1.7 by Jay Pipes
Merged in remove-timezone work
196
}
197
1999.4.9 by Brian Aker
Created EPOCH
198
int Epoch::store(int64_t from, bool)
907.1.7 by Jay Pipes
Merged in remove-timezone work
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
  {
1775.5.2 by earney
removed old commented out statements and uncommmeted out first occurance of stringstream in date.cc since it sets the precision.
209
    /* Convert the integer to a string using boost::lexical_cast */
1775.5.1 by earney
modified files containing stringstream to use boost:lexical_cast instead as
210
    std::string tmp(boost::lexical_cast<std::string>(from));
907.1.7 by Jay Pipes
Merged in remove-timezone work
211
212
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
213
    return 2;
214
  }
215
2016.1.7 by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to
216
  time_t tmp;
217
  temporal.to_time_t(tmp);
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
218
219
  pack_num(tmp);
220
907.1.7 by Jay Pipes
Merged in remove-timezone work
221
  return 0;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
222
}
223
1999.4.9 by Brian Aker
Created EPOCH
224
double Epoch::val_real(void)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
225
{
1999.4.9 by Brian Aker
Created EPOCH
226
  return (double) Epoch::val_int();
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
227
}
228
1999.4.9 by Brian Aker
Created EPOCH
229
int64_t Epoch::val_int(void)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
230
{
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
231
  uint64_t temp;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
232
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
233
  ASSERT_COLUMN_MARKED_FOR_READ;
234
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
235
  unpack_num(temp);
907.1.8 by Jay Pipes
Final removal of timezones
236
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
237
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
238
  (void) temporal.from_time_t((time_t) temp);
239
240
  /* We must convert into a "timestamp-formatted integer" ... */
241
  int64_t result;
242
  temporal.to_int64_t(&result);
243
  return result;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
244
}
245
1999.4.9 by Brian Aker
Created EPOCH
246
String *Epoch::val_str(String *val_buffer, String *)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
247
{
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
248
  uint64_t temp= 0;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
249
  char *to;
1079.3.1 by Stewart Smith
Change temporal to_string routines to use snprintf instead of sprintf.
250
  int to_len= field_length + 1;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
251
1079.3.1 by Stewart Smith
Change temporal to_string routines to use snprintf instead of sprintf.
252
  val_buffer->alloc(to_len);
907.1.8 by Jay Pipes
Final removal of timezones
253
  to= (char *) val_buffer->ptr();
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
254
1999.4.5 by Brian Aker
Get all of the endian stuff out of the classes.
255
  unpack_num(temp);
907.1.8 by Jay Pipes
Final removal of timezones
256
257
  val_buffer->set_charset(&my_charset_bin);	/* Safety */
258
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
259
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
260
  (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.
261
262
  int rlen;
263
  rlen= temporal.to_string(to, to_len);
264
  assert(rlen < to_len);
265
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.
266
  val_buffer->length(rlen);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
267
  return val_buffer;
268
}
269
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
270
bool Epoch::get_date(type::Time *ltime, uint32_t)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
271
{
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
272
  uint64_t temp;
907.1.8 by Jay Pipes
Final removal of timezones
273
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
274
  unpack_num(temp);
907.1.8 by Jay Pipes
Final removal of timezones
275
  
276
  memset(ltime, 0, sizeof(*ltime));
277
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
278
  Timestamp temporal;
907.1.8 by Jay Pipes
Final removal of timezones
279
  (void) temporal.from_time_t((time_t) temp);
280
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
281
  /* @TODO Goodbye the below code when type::Time is finally gone.. */
907.1.8 by Jay Pipes
Final removal of timezones
282
283
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
284
  ltime->year= temporal.years();
285
  ltime->month= temporal.months();
286
  ltime->day= temporal.days();
287
  ltime->hour= temporal.hours();
288
  ltime->minute= temporal.minutes();
289
  ltime->second= temporal.seconds();
290
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
291
  return 0;
292
}
293
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
294
bool Epoch::get_time(type::Time *ltime)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
295
{
1999.4.9 by Brian Aker
Created EPOCH
296
  return Epoch::get_date(ltime,0);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
297
}
298
1999.4.9 by Brian Aker
Created EPOCH
299
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
300
{
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
301
  uint64_t a,b;
1999.4.5 by Brian Aker
Get all of the endian stuff out of the classes.
302
303
  unpack_num(a, a_ptr);
304
  unpack_num(b, b_ptr);
305
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
306
  return (a < b) ? -1 : (a > b) ? 1 : 0;
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
307
}
308
309
1999.4.9 by Brian Aker
Created EPOCH
310
void Epoch::sort_string(unsigned char *to,uint32_t )
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
311
{
312
#ifdef WORDS_BIGENDIAN
1830.1.3 by Brian Aker
Fix for Solaris
313
  if (!getTable() || !getTable()->getShare()->db_low_byte_first)
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
314
  {
315
    to[0] = ptr[0];
316
    to[1] = ptr[1];
317
    to[2] = ptr[2];
318
    to[3] = ptr[3];
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
319
    to[4] = ptr[4];
320
    to[5] = ptr[5];
321
    to[6] = ptr[6];
322
    to[7] = ptr[7];
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
323
  }
324
  else
325
#endif
326
  {
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
327
    to[0] = ptr[7];
328
    to[1] = ptr[6];
329
    to[2] = ptr[5];
330
    to[3] = ptr[4];
331
    to[4] = ptr[3];
332
    to[5] = ptr[2];
333
    to[6] = ptr[1];
334
    to[7] = ptr[0];
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
335
  }
336
}
337
1999.4.9 by Brian Aker
Created EPOCH
338
void Epoch::sql_type(String &res) const
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
339
{
340
  res.set_ascii(STRING_WITH_LEN("timestamp"));
341
}
342
1999.4.9 by Brian Aker
Created EPOCH
343
void Epoch::set_time()
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
344
{
1660.1.3 by Brian Aker
Encapsulate Table in field
345
  Session *session= getTable() ? getTable()->in_use : current_session;
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
346
  time_t tmp= session->query_start();
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
347
  set_notnull();
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
348
  pack_num(tmp);
173.1.6 by Toru Maesaka
ripped out TIMESTAMP and move to field/
349
}
350
1999.4.9 by Brian Aker
Created EPOCH
351
void Epoch::set_default()
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
352
{
1660.1.3 by Brian Aker
Encapsulate Table in field
353
  if (getTable()->timestamp_field == this &&
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
354
      unireg_check != TIMESTAMP_UN_FIELD)
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
355
  {
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
356
    set_time();
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
357
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
358
  else
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
359
  {
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
360
    Field::set_default();
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
361
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
362
}
363
1999.4.9 by Brian Aker
Created EPOCH
364
long Epoch::get_timestamp(bool *null_value)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
365
{
366
  if ((*null_value= is_null()))
367
    return 0;
1999.4.5 by Brian Aker
Get all of the endian stuff out of the classes.
368
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
369
  uint64_t tmp;
1999.4.5 by Brian Aker
Get all of the endian stuff out of the classes.
370
  return unpack_num(tmp);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
371
}
372
1999.4.9 by Brian Aker
Created EPOCH
373
size_t Epoch::max_string_length()
1999.4.4 by Brian Aker
First pass through on timestamp.
374
{
1999.4.6 by Brian Aker
Fix pack/unpack to go through common functions.
375
  return sizeof(uint64_t);
1999.4.4 by Brian Aker
First pass through on timestamp.
376
}
377
1999.4.9 by Brian Aker
Created EPOCH
378
} /* namespace field */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
379
} /* namespace drizzled */