~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/datetime.cc

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

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
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/field/datetime.h>
 
24
#include <drizzled/error.h>
 
25
#include CMATH_H
 
26
 
 
27
#if defined(CMATH_NAMESPACE)
 
28
using namespace CMATH_NAMESPACE;
 
29
#endif
27
30
 
28
31
/****************************************************************************
29
32
** datetime type
33
36
****************************************************************************/
34
37
 
35
38
int Field_datetime::store(const char *from,
36
 
                          uint len,
 
39
                          uint32_t len,
37
40
                          const CHARSET_INFO * const cs __attribute__((unused)))
38
41
{
39
42
  DRIZZLE_TIME time_tmp;
40
43
  int error;
41
44
  uint64_t tmp= 0;
42
45
  enum enum_drizzle_timestamp_type func_res;
43
 
  THD *thd= table ? table->in_use : current_thd;
 
46
  Session *session= table ? table->in_use : current_session;
44
47
 
45
48
  func_res= str_to_datetime(from, len, &time_tmp,
46
49
                            (TIME_FUZZY_DATE |
47
 
                             (thd->variables.sql_mode &
 
50
                             (session->variables.sql_mode &
48
51
                              (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
49
52
                            &error);
50
53
  if ((int) func_res > (int) DRIZZLE_TIMESTAMP_ERROR)
91
94
  DRIZZLE_TIME not_used;
92
95
  int error;
93
96
  int64_t initial_nr= nr;
94
 
  THD *thd= table ? table->in_use : current_thd;
 
97
  Session *session= table ? table->in_use : current_session;
95
98
 
96
99
  nr= number_to_datetime(nr, &not_used, (TIME_FUZZY_DATE |
97
 
                                         (thd->variables.sql_mode &
 
100
                                         (session->variables.sql_mode &
98
101
                                          (MODE_NO_ZERO_DATE |
99
102
                                           MODE_INVALID_DATES))), &error);
100
103
 
101
 
  if (nr == -1LL)
 
104
  if (nr == INT64_C(-1))
102
105
  {
103
106
    nr= 0;
104
107
    error= 2;
122
125
}
123
126
 
124
127
 
125
 
int Field_datetime::store_time(DRIZZLE_TIME *ltime,timestamp_type time_type)
 
128
int Field_datetime::store_time(DRIZZLE_TIME *ltime,
 
129
                               enum enum_drizzle_timestamp_type time_type)
126
130
{
127
131
  int64_t tmp;
128
132
  int error= 0;
133
137
  if (time_type == DRIZZLE_TIMESTAMP_DATE ||
134
138
      time_type == DRIZZLE_TIMESTAMP_DATETIME)
135
139
  {
136
 
    tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*1000000LL+
 
140
    tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*INT64_C(1000000)+
137
141
         (ltime->hour*10000L+ltime->minute*100+ltime->second));
138
142
    if (check_date(ltime, tmp != 0,
139
143
                   (TIME_FUZZY_DATE |
140
 
                    (current_thd->variables.sql_mode &
 
144
                    (current_session->variables.sql_mode &
141
145
                     (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
142
146
    {
143
147
      char buff[MAX_DATE_STRING_REP_LENGTH];
211
215
    Avoid problem with slow int64_t arithmetic and sprintf
212
216
  */
213
217
 
214
 
  part1=(long) (tmp/1000000LL);
215
 
  part2=(long) (tmp - (uint64_t) part1*1000000LL);
 
218
  part1=(long) (tmp/INT64_C(1000000));
 
219
  part2=(long) (tmp - (uint64_t) part1*INT64_C(1000000));
216
220
 
217
221
  pos=(char*) val_buffer->ptr() + MAX_DATETIME_WIDTH;
218
222
  *pos--=0;
238
242
  return val_buffer;
239
243
}
240
244
 
241
 
bool Field_datetime::get_date(DRIZZLE_TIME *ltime, uint fuzzydate)
 
245
bool Field_datetime::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
242
246
{
243
247
  int64_t tmp=Field_datetime::val_int();
244
248
  uint32_t part1,part2;
245
 
  part1=(uint32_t) (tmp/1000000LL);
246
 
  part2=(uint32_t) (tmp - (uint64_t) part1*1000000LL);
 
249
  part1=(uint32_t) (tmp/INT64_C(1000000));
 
250
  part2=(uint32_t) (tmp - (uint64_t) part1*INT64_C(1000000));
247
251
 
248
252
  ltime->time_type=     DRIZZLE_TIMESTAMP_DATETIME;
249
253
  ltime->neg=           0;
262
266
  return Field_datetime::get_date(ltime,0);
263
267
}
264
268
 
265
 
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr)
 
269
int Field_datetime::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
266
270
{
267
271
  int64_t a,b;
268
272
#ifdef WORDS_BIGENDIAN
281
285
    ((uint64_t) a > (uint64_t) b) ? 1 : 0;
282
286
}
283
287
 
284
 
void Field_datetime::sort_string(uchar *to,uint length __attribute__((unused)))
 
288
void Field_datetime::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
285
289
{
286
290
#ifdef WORDS_BIGENDIAN
287
291
  if (!table || !table->s->db_low_byte_first)