~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/extract.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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include "drizzled/server_includes.h"
 
21
#include CSTDINT_H
22
22
#include "drizzled/temporal.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/session.h"
25
25
#include "drizzled/calendar.h"
26
26
#include "drizzled/function/time/extract.h"
27
27
 
28
 
namespace drizzled
29
 
{
30
 
 
31
28
/*
32
29
   'interval_names' reflects the order of the enumeration interval_type.
33
30
   See item/time.h
70
67
  case INTERVAL_HOUR_MICROSECOND: max_length=13; date_value=0; break;
71
68
  case INTERVAL_MINUTE_MICROSECOND: max_length=11; date_value=0; break;
72
69
  case INTERVAL_SECOND_MICROSECOND: max_length=9; date_value=0; break;
73
 
  case INTERVAL_LAST: assert(0); break;
 
70
  case INTERVAL_LAST: assert(0); break; /* purecov: deadcode */
74
71
  }
75
72
}
76
73
 
86
83
  }
87
84
 
88
85
  /* We could have either a datetime or a time.. */
89
 
  DateTime datetime_temporal;
90
 
  Time time_temporal;
 
86
  drizzled::DateTime datetime_temporal;
 
87
  drizzled::Time time_temporal;
91
88
 
92
89
  /* Abstract pointer type we'll use in the final switch */
93
 
  Temporal *temporal;
 
90
  drizzled::Temporal *temporal;
94
91
 
95
92
  if (date_value)
96
93
  {
113
110
          char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
114
111
          String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
115
112
          String *res= args[0]->val_str(&tmp);
116
 
 
117
 
          if (res && (res != &tmp))
118
 
          {
119
 
            tmp.copy(*res);
120
 
          }
121
 
 
122
 
          if (! datetime_temporal.from_string(tmp.c_ptr(), tmp.length()))
 
113
          if (! datetime_temporal.from_string(res->c_ptr(), res->length()))
123
114
          {
124
115
            /* 
125
116
            * Could not interpret the function argument as a temporal value, 
126
117
            * so throw an error and return 0
127
118
            */
128
 
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
119
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
129
120
            return 0;
130
121
          }
131
122
        }
147
138
 
148
139
          res= args[0]->val_str(&tmp);
149
140
 
150
 
          if (res && (res != &tmp))
151
 
          {
152
 
            tmp.copy(*res);
153
 
          }
154
 
 
155
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
141
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
156
142
          return 0;
157
143
        }
158
144
    }
183
169
    char time_buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
184
170
    String tmp_time(time_buff,sizeof(time_buff), &my_charset_utf8_bin);
185
171
    String *time_res= args[0]->val_str(&tmp_time);
186
 
 
187
 
    if (time_res && (time_res != &tmp_time))
188
 
    {
189
 
      tmp_time.copy(*time_res);
190
 
    }
191
 
 
192
 
    if (! time_temporal.from_string(tmp_time.c_ptr(), tmp_time.length()))
 
172
    if (! time_temporal.from_string(time_res->c_ptr(), time_res->length()))
193
173
    {
194
174
      /* 
195
175
       * OK, we failed to match the first argument as a string
214
194
            char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
215
195
            String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
216
196
            String *res= args[0]->val_str(&tmp);
217
 
 
218
 
            if (res && (res != &tmp))
219
 
            {
220
 
              tmp.copy(*res);
221
 
            }
222
 
 
223
 
            if (! datetime_temporal.from_string(tmp.c_ptr(), tmp.length()))
 
197
            if (! datetime_temporal.from_string(res->c_ptr(), res->length()))
224
198
            {
225
199
              /* 
226
200
               * Could not interpret the function argument as a temporal value, 
227
201
               * so throw an error and return 0
228
202
               */
229
 
              my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
203
              my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
230
204
              return 0;
231
205
            }
232
206
          }
275
249
    case INTERVAL_WEEK:
276
250
      return iso_week_number_from_gregorian_date(temporal->years()
277
251
                                               , temporal->months()
278
 
                                               , temporal->days());
 
252
                                               , temporal->days()
 
253
                                               , NULL); /* NULL is year_out parameter, which is not needed */
279
254
    case INTERVAL_DAY:
280
255
      return (int64_t) temporal->days();
281
256
    case INTERVAL_DAY_HOUR:     
346
321
    case INTERVAL_LAST: 
347
322
    default:
348
323
        assert(0); 
349
 
        return 0;
 
324
        return 0;  /* purecov: deadcode */
350
325
  }
351
326
}
352
327
 
366
341
      return 0;
367
342
  return 1;
368
343
}
369
 
 
370
 
} /* namespace drizzled */