~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/extract.cc

  • Committer: Monty Taylor
  • Date: 2010-06-26 03:52:47 UTC
  • mfrom: (1637.1.5 staging)
  • Revision ID: mordred@inaugust.com-20100626035247-i0iq4sd6wqzfisyy
Merged in staging changes: Mark's syslog patch and vijay's program_options.

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
113
113
          char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
114
114
          String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
115
115
          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()))
 
116
          if (! datetime_temporal.from_string(res->c_ptr(), res->length()))
123
117
          {
124
118
            /* 
125
119
            * Could not interpret the function argument as a temporal value, 
126
120
            * so throw an error and return 0
127
121
            */
128
 
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
122
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
129
123
            return 0;
130
124
          }
131
125
        }
147
141
 
148
142
          res= args[0]->val_str(&tmp);
149
143
 
150
 
          if (res && (res != &tmp))
151
 
          {
152
 
            tmp.copy(*res);
153
 
          }
154
 
 
155
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
144
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
156
145
          return 0;
157
146
        }
158
147
    }
183
172
    char time_buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
184
173
    String tmp_time(time_buff,sizeof(time_buff), &my_charset_utf8_bin);
185
174
    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()))
 
175
    if (! time_temporal.from_string(time_res->c_ptr(), time_res->length()))
193
176
    {
194
177
      /* 
195
178
       * OK, we failed to match the first argument as a string
214
197
            char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
215
198
            String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
216
199
            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()))
 
200
            if (! datetime_temporal.from_string(res->c_ptr(), res->length()))
224
201
            {
225
202
              /* 
226
203
               * Could not interpret the function argument as a temporal value, 
227
204
               * so throw an error and return 0
228
205
               */
229
 
              my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
206
              my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
230
207
              return 0;
231
208
            }
232
209
          }
275
252
    case INTERVAL_WEEK:
276
253
      return iso_week_number_from_gregorian_date(temporal->years()
277
254
                                               , temporal->months()
278
 
                                               , temporal->days());
 
255
                                               , temporal->days()
 
256
                                               , NULL); /* NULL is year_out parameter, which is not needed */
279
257
    case INTERVAL_DAY:
280
258
      return (int64_t) temporal->days();
281
259
    case INTERVAL_DAY_HOUR: