~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_interval.cc

  • Committer: Monty Taylor
  • Date: 2010-01-12 21:34:24 UTC
  • mto: This revision was merged to the branch mainline in revision 1268.
  • Revision ID: mordred@inaugust.com-20100112213424-6mslywtlca49mvnk
Updated to pandora-buld v0.94

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
 
 
22
 
#include <drizzled/internal/m_string.h>
23
 
#include <drizzled/error.h>
24
 
#include <drizzled/session.h>
25
 
#include <drizzled/current_session.h>
26
 
#include <drizzled/function/time/date.h>
27
 
#include <drizzled/temporal_interval.h>
28
 
#include <drizzled/time_functions.h>
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
bool TemporalInterval::initFromItem(Item *args,
34
 
                                    interval_type int_type,
35
 
                                    String *str_value)
 
20
#include "config.h"
 
21
#include "drizzled/internal/m_string.h"
 
22
#include "drizzled/error.h"
 
23
#include "drizzled/session.h"
 
24
#include "config.h"
 
25
#include "drizzled/function/time/date.h"
 
26
#include "drizzled/temporal_interval.h"
 
27
#include "drizzled/time_functions.h"
 
28
 
 
29
bool drizzled::TemporalInterval::initFromItem(Item *args, interval_type int_type, String *str_value)
36
30
{
37
31
  uint64_t array[MAX_STRING_ELEMENTS];
38
32
  int64_t value= 0;
187
181
  return false;
188
182
}
189
183
 
190
 
bool TemporalInterval::addDate(type::Time *ltime, interval_type int_type)
 
184
bool drizzled::TemporalInterval::addDate(DRIZZLE_TIME *ltime, interval_type int_type)
191
185
{
192
186
  long period, sign;
193
187
 
212
206
  case INTERVAL_DAY_MINUTE:
213
207
  case INTERVAL_DAY_HOUR:
214
208
    int64_t sec, days, daynr, microseconds, extra_sec;
215
 
    ltime->time_type= type::DRIZZLE_TIMESTAMP_DATETIME; // Return full date
 
209
    ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME; // Return full date
216
210
    microseconds= ltime->second_part + sign*second_part;
217
211
    extra_sec= microseconds/1000000L;
218
212
    microseconds= microseconds%1000000L;
242
236
    /* Day number from year 0 to 9999-12-31 */
243
237
    if ((uint64_t) daynr > MAX_DAY_NUMBER)
244
238
      goto invalid_date;
245
 
    get_date_from_daynr((long) daynr, &ltime->year, &ltime->month, &ltime->day);
 
239
    get_date_from_daynr((long) daynr, &ltime->year, &ltime->month,
 
240
        &ltime->day);
246
241
    break;
247
242
  case INTERVAL_DAY:
248
243
  case INTERVAL_WEEK:
286
281
 
287
282
invalid_date:
288
283
  push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
289
 
                      ER_DATETIME_FUNCTION_OVERFLOW,
290
 
                      ER(ER_DATETIME_FUNCTION_OVERFLOW),
291
 
                      "datetime");
 
284
      ER_DATETIME_FUNCTION_OVERFLOW,
 
285
      ER(ER_DATETIME_FUNCTION_OVERFLOW),
 
286
      "datetime");
292
287
null_date:
293
288
  return 1;
294
289
}
295
290
 
296
 
bool TemporalInterval::getIntervalFromString(const char *str,
297
 
                                             uint32_t length,
298
 
                                             const CHARSET_INFO * const cs,
299
 
                                             uint32_t count, uint64_t *values,
300
 
                                             bool transform_msec)
 
291
bool drizzled::TemporalInterval::getIntervalFromString(const char *str,uint32_t length, const CHARSET_INFO * const cs,
 
292
    uint32_t count, uint64_t *values,
 
293
    bool transform_msec)
301
294
{
302
295
  const char *end= str+length;
303
296
  uint32_t x;
311
304
    const char *start= str;
312
305
    for (value= 0 ; str != end && my_isdigit(cs,*str) ; str++)
313
306
      value= value * 10L + (int64_t) (*str - '0');
314
 
    if (transform_msec && (x == count - 1 || str == end)) // microseconds always last
 
307
    if (transform_msec && x == count - 1) // microseconds always last
315
308
    {
316
309
      long msec_length= 6 - (str - start);
317
310
      if (msec_length > 0)
323
316
    if (str == end && x != count-1)
324
317
    {
325
318
      x++;
326
 
      /* Change values[0...x-1] -> values[count-x...count-1] */
327
 
      internal::bmove_upp((unsigned char*) (values+count),
328
 
                          (unsigned char*) (values+x),
329
 
                          sizeof(*values)*x);
 
319
      /* Change values[0...x-1] -> values[0...count-1] */
 
320
      bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+x),
 
321
          sizeof(*values)*x);
330
322
      memset(values, 0, sizeof(*values)*(count-x));
331
323
      break;
332
324
    }
333
325
  }
334
326
  return (str != end);
335
327
}
336
 
 
337
 
} /* namespace drizzled */