~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal_interval.cc

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
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"
 
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>
28
29
 
29
30
namespace drizzled
30
31
{
37
38
  int64_t value= 0;
38
39
  const char *str= NULL;
39
40
  size_t length= 0;
40
 
  const CHARSET_INFO * const cs= str_value->charset();
 
41
  const charset_info_st * const cs= str_value->charset();
41
42
 
42
43
 
43
44
  // Types <= microsecond can be converted as an integer
63
64
    str= res->ptr();
64
65
    const char *end= str+res->length();
65
66
    // Skip the whitespace
66
 
    while (str != end && my_isspace(cs,*str))
 
67
    while (str != end && cs->isspace(*str))
67
68
      str++;
68
69
    if (str != end && *str == '-')
69
70
    {
186
187
  return false;
187
188
}
188
189
 
189
 
bool TemporalInterval::addDate(DRIZZLE_TIME *ltime, interval_type int_type)
 
190
bool TemporalInterval::addDate(type::Time *ltime, interval_type int_type)
190
191
{
191
192
  long period, sign;
192
193
 
211
212
  case INTERVAL_DAY_MINUTE:
212
213
  case INTERVAL_DAY_HOUR:
213
214
    int64_t sec, days, daynr, microseconds, extra_sec;
214
 
    ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME; // Return full date
 
215
    ltime->time_type= type::DRIZZLE_TIMESTAMP_DATETIME; // Return full date
215
216
    microseconds= ltime->second_part + sign*second_part;
216
217
    extra_sec= microseconds/1000000L;
217
218
    microseconds= microseconds%1000000L;
241
242
    /* Day number from year 0 to 9999-12-31 */
242
243
    if ((uint64_t) daynr > MAX_DAY_NUMBER)
243
244
      goto invalid_date;
244
 
    get_date_from_daynr((long) daynr, &ltime->year, &ltime->month,
245
 
        &ltime->day);
 
245
    get_date_from_daynr((long) daynr, &ltime->year, &ltime->month, &ltime->day);
246
246
    break;
247
247
  case INTERVAL_DAY:
248
248
  case INTERVAL_WEEK:
286
286
 
287
287
invalid_date:
288
288
  push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
289
 
      ER_DATETIME_FUNCTION_OVERFLOW,
290
 
      ER(ER_DATETIME_FUNCTION_OVERFLOW),
291
 
      "datetime");
 
289
                      ER_DATETIME_FUNCTION_OVERFLOW,
 
290
                      ER(ER_DATETIME_FUNCTION_OVERFLOW),
 
291
                      "datetime");
292
292
null_date:
293
293
  return 1;
294
294
}
295
295
 
296
296
bool TemporalInterval::getIntervalFromString(const char *str,
297
297
                                             uint32_t length,
298
 
                                             const CHARSET_INFO * const cs,
 
298
                                             const charset_info_st * const cs,
299
299
                                             uint32_t count, uint64_t *values,
300
300
                                             bool transform_msec)
301
301
{
302
302
  const char *end= str+length;
303
303
  uint32_t x;
304
304
 
305
 
  while (str != end && !my_isdigit(cs,*str))
 
305
  while (str != end && !cs->isdigit(*str))
306
306
    str++;
307
307
 
308
308
  for (x= 0 ; x < count ; x++)
309
309
  {
310
310
    int64_t value;
311
311
    const char *start= str;
312
 
    for (value= 0 ; str != end && my_isdigit(cs,*str) ; str++)
 
312
    for (value= 0 ; str != end && cs->isdigit(*str) ; str++)
313
313
      value= value * 10L + (int64_t) (*str - '0');
314
314
    if (transform_msec && (x == count - 1 || str == end)) // microseconds always last
315
315
    {
318
318
        value*= (long) log_10_int[msec_length];
319
319
    }
320
320
    values[x]= value;
321
 
    while (str != end && !my_isdigit(cs,*str))
 
321
    while (str != end && !cs->isdigit(*str))
322
322
      str++;
323
323
    if (str == end && x != count-1)
324
324
    {