~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Monty Taylor
  • Date: 2008-10-08 01:10:45 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: monty@inaugust.com-20081008011045-zqozbc81f8qhmxok
Get rid of pragma interface/pragma implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#ifdef USE_PRAGMA_IMPLEMENTATION
22
 
#pragma implementation                          // gcc: Class implementation
23
 
#endif
24
21
 
25
 
#include "drizzle/server/field/timestamp.h"
 
22
#include <drizzled/server_includes.h>
 
23
#include <drizzled/field/timestamp.h>
26
24
 
27
25
/**
28
26
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to 
68
66
  exception is different behavior of old/new timestamps during ALTER TABLE.
69
67
 */
70
68
 
71
 
Field_timestamp::Field_timestamp(uchar *ptr_arg,
72
 
                                 uint32_t len_arg __attribute__((__unused__)),
73
 
                                 uchar *null_ptr_arg, uchar null_bit_arg,
 
69
Field_timestamp::Field_timestamp(unsigned char *ptr_arg,
 
70
                                 uint32_t len_arg __attribute__((unused)),
 
71
                                 unsigned char *null_ptr_arg, unsigned char null_bit_arg,
74
72
                                 enum utype unireg_check_arg,
75
73
                                 const char *field_name_arg,
76
74
                                 TABLE_SHARE *share,
77
 
                                 CHARSET_INFO *cs)
 
75
                                 const CHARSET_INFO * const cs)
78
76
  :Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
79
77
             unireg_check_arg, field_name_arg, cs)
80
78
{
81
79
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
82
 
  flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
80
  flags|= UNSIGNED_FLAG;
83
81
  if (!share->timestamp_field && unireg_check != NONE)
84
82
  {
85
83
    /* This timestamp has auto-update */
93
91
 
94
92
Field_timestamp::Field_timestamp(bool maybe_null_arg,
95
93
                                 const char *field_name_arg,
96
 
                                 CHARSET_INFO *cs)
97
 
  :Field_str((uchar*) 0, MAX_DATETIME_WIDTH,
98
 
             maybe_null_arg ? (uchar*) "": 0, 0,
 
94
                                 const CHARSET_INFO * const cs)
 
95
  :Field_str((unsigned char*) 0, MAX_DATETIME_WIDTH,
 
96
             maybe_null_arg ? (unsigned char*) "": 0, 0,
99
97
             NONE, field_name_arg, cs)
100
98
{
101
99
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
102
 
  flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
100
  flags|= UNSIGNED_FLAG;
103
101
    if (unireg_check != TIMESTAMP_DN_FIELD)
104
102
      flags|= ON_UPDATE_NOW_FLAG;
105
103
}
141
139
 
142
140
 
143
141
int Field_timestamp::store(const char *from,
144
 
                           uint len,
145
 
                           CHARSET_INFO *cs __attribute__((__unused__)))
 
142
                           uint32_t len,
 
143
                           const CHARSET_INFO * const cs __attribute__((unused)))
146
144
{
147
 
  MYSQL_TIME l_time;
 
145
  DRIZZLE_TIME l_time;
148
146
  my_time_t tmp= 0;
149
147
  int error;
150
148
  bool have_smth_to_conv;
153
151
 
154
152
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
155
153
  have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) >
156
 
                      MYSQL_TIMESTAMP_ERROR);
 
154
                      DRIZZLE_TIMESTAMP_ERROR);
157
155
 
158
156
  if (error || !have_smth_to_conv)
159
157
  {
160
158
    error= 1;
161
 
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
162
 
                         from, len, MYSQL_TIMESTAMP_DATETIME, 1);
 
159
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
 
160
                         from, len, DRIZZLE_TIMESTAMP_DATETIME, 1);
163
161
  }
164
162
 
165
163
  /* Only convert a correct date (not a zero date) */
167
165
  {
168
166
    if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
169
167
    {
170
 
      set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
 
168
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
171
169
                           ER_WARN_DATA_OUT_OF_RANGE,
172
 
                           from, len, MYSQL_TIMESTAMP_DATETIME, !error);
 
170
                           from, len, DRIZZLE_TIMESTAMP_DATETIME, !error);
173
171
      error= 1;
174
172
    }
175
173
    else if (in_dst_time_gap)
176
174
    {
177
 
      set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
 
175
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
178
176
                           ER_WARN_INVALID_TIMESTAMP,
179
 
                           from, len, MYSQL_TIMESTAMP_DATETIME, !error);
 
177
                           from, len, DRIZZLE_TIMESTAMP_DATETIME, !error);
180
178
      error= 1;
181
179
    }
182
180
  }
190
188
  int error= 0;
191
189
  if (nr < 0 || nr > 99991231235959.0)
192
190
  {
193
 
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
 
191
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
194
192
                         ER_WARN_DATA_OUT_OF_RANGE,
195
 
                         nr, MYSQL_TIMESTAMP_DATETIME);
 
193
                         nr, DRIZZLE_TIMESTAMP_DATETIME);
196
194
    nr= 0;                                      // Avoid overflow on buff
197
195
    error= 1;
198
196
  }
202
200
 
203
201
 
204
202
int Field_timestamp::store(int64_t nr,
205
 
                           bool unsigned_val __attribute__((__unused__)))
 
203
                           bool unsigned_val __attribute__((unused)))
206
204
{
207
 
  MYSQL_TIME l_time;
 
205
  DRIZZLE_TIME l_time;
208
206
  my_time_t timestamp= 0;
209
207
  int error;
210
208
  bool in_dst_time_gap;
212
210
 
213
211
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
214
212
  int64_t tmp= number_to_datetime(nr, &l_time, (thd->variables.sql_mode &
215
 
                                                 MODE_NO_ZERO_DATE) |
216
 
                                   MODE_NO_ZERO_IN_DATE, &error);
217
 
  if (tmp == -1LL)
 
213
                                                 MODE_NO_ZERO_DATE), &error);
 
214
  if (tmp == INT64_C(-1))
218
215
  {
219
216
    error= 2;
220
217
  }
223
220
  {
224
221
    if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
225
222
    {
226
 
      set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
 
223
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
227
224
                           ER_WARN_DATA_OUT_OF_RANGE,
228
 
                           nr, MYSQL_TIMESTAMP_DATETIME, 1);
 
225
                           nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
229
226
      error= 1;
230
227
    }
231
228
    if (in_dst_time_gap)
232
229
    {
233
 
      set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
 
230
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
234
231
                           ER_WARN_INVALID_TIMESTAMP,
235
 
                           nr, MYSQL_TIMESTAMP_DATETIME, 1);
 
232
                           nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
236
233
      error= 1;
237
234
    }
238
235
  } else if (error)
239
 
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
240
 
                         WARN_DATA_TRUNCATED,
241
 
                         nr, MYSQL_TIMESTAMP_DATETIME, 1);
 
236
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
237
                         ER_WARN_DATA_TRUNCATED,
 
238
                         nr, DRIZZLE_TIMESTAMP_DATETIME, 1);
242
239
 
243
240
  store_timestamp(timestamp);
244
241
  return error;
252
249
int64_t Field_timestamp::val_int(void)
253
250
{
254
251
  uint32_t temp;
255
 
  MYSQL_TIME time_tmp;
 
252
  DRIZZLE_TIME time_tmp;
256
253
  THD  *thd= table ? table->in_use : current_thd;
257
254
 
258
255
  thd->time_zone_used= 1;
268
265
  
269
266
  thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp);
270
267
  
271
 
  return time_tmp.year * 10000000000LL + time_tmp.month * 100000000LL +
272
 
         time_tmp.day * 1000000L + time_tmp.hour * 10000L +
 
268
  return time_tmp.year * INT64_C(10000000000) +
 
269
         time_tmp.month * INT64_C(100000000) +
 
270
         time_tmp.day * 1000000 + time_tmp.hour * 10000 +
273
271
         time_tmp.minute * 100 + time_tmp.second;
274
272
}
275
273
 
277
275
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
278
276
{
279
277
  uint32_t temp, temp2;
280
 
  MYSQL_TIME time_tmp;
 
278
  DRIZZLE_TIME time_tmp;
281
279
  THD *thd= table ? table->in_use : current_thd;
282
280
  char *to;
283
281
 
346
344
}
347
345
 
348
346
 
349
 
bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
 
347
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
350
348
{
351
349
  long temp;
352
350
  THD *thd= table ? table->in_use : current_thd;
361
359
  {                                   /* Zero time is "000000" */
362
360
    if (fuzzydate & TIME_NO_ZERO_DATE)
363
361
      return 1;
364
 
    bzero((char*) ltime,sizeof(*ltime));
 
362
    memset(ltime, 0, sizeof(*ltime));
365
363
  }
366
364
  else
367
365
  {
370
368
  return 0;
371
369
}
372
370
 
373
 
bool Field_timestamp::get_time(MYSQL_TIME *ltime)
 
371
bool Field_timestamp::get_time(DRIZZLE_TIME *ltime)
374
372
{
375
373
  return Field_timestamp::get_date(ltime,0);
376
374
}
378
376
 
379
377
bool Field_timestamp::send_binary(Protocol *protocol)
380
378
{
381
 
  MYSQL_TIME tm;
 
379
  DRIZZLE_TIME tm;
382
380
  Field_timestamp::get_date(&tm, 0);
383
381
  return protocol->store(&tm);
384
382
}
385
383
 
386
384
 
387
 
int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr)
 
385
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
388
386
{
389
387
  int32_t a,b;
390
388
#ifdef WORDS_BIGENDIAN
403
401
}
404
402
 
405
403
 
406
 
void Field_timestamp::sort_string(uchar *to,uint length __attribute__((unused)))
 
404
void Field_timestamp::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
407
405
{
408
406
#ifdef WORDS_BIGENDIAN
409
407
  if (!table || !table->s->db_low_byte_first)