~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_interval.cc

  • Committer: Brian Aker
  • Date: 2009-08-18 07:19:56 UTC
  • mfrom: (1116.1.3 stewart)
  • mto: This revision was merged to the branch mainline in revision 1118.
  • Revision ID: brian@gaz-20090818071956-nfpoe9rp3i7p50kx
Merge my branch from Stewart into one branch

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