~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/item_timefunc.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
 
1
/*
 
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
 
17
19
/**
294
296
  for (; ptr != end && val != val_end; ptr++)
295
297
  {
296
298
    /* Skip pre-space between each argument */
297
 
    while (val != val_end && my_isspace(cs, *val))
298
 
      val++;
 
299
    if ((val+= cs->cset->scan(cs, val, val_end, MY_SEQ_SPACES)) >= val_end)
 
300
      break;
299
301
 
300
302
    if (*ptr == '%' && ptr+1 != end)
301
303
    {
648
650
                    system_charset_info);
649
651
        break;
650
652
      case 'W':
651
 
        if (type == MYSQL_TIMESTAMP_TIME)
 
653
        if (type == MYSQL_TIMESTAMP_TIME || !(l_time->month || l_time->year))
652
654
          return 1;
653
655
        weekday= calc_weekday(calc_daynr(l_time->year,l_time->month,
654
656
                              l_time->day),0);
657
659
                    system_charset_info);
658
660
        break;
659
661
      case 'a':
660
 
        if (type == MYSQL_TIMESTAMP_TIME)
 
662
        if (type == MYSQL_TIMESTAMP_TIME || !(l_time->month || l_time->year))
661
663
          return 1;
662
664
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
663
665
                             l_time->day),0);
754
756
        str->append(hours_i < 12 ? "AM" : "PM",2);
755
757
        break;
756
758
      case 'r':
757
 
        length= my_sprintf(intbuff, 
758
 
                   (intbuff, 
759
 
                    ((l_time->hour % 24) < 12) ?
760
 
                    "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
761
 
                    (l_time->hour+11)%12+1,
762
 
                    l_time->minute,
763
 
                    l_time->second));
 
759
        length= sprintf(intbuff, ((l_time->hour % 24) < 12) ?
 
760
                        "%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
 
761
                        (l_time->hour+11)%12+1,
 
762
                        l_time->minute,
 
763
                        l_time->second);
764
764
        str->append(intbuff, length);
765
765
        break;
766
766
      case 'S':
769
769
        str->append_with_prefill(intbuff, length, 2, '0');
770
770
        break;
771
771
      case 'T':
772
 
        length= my_sprintf(intbuff, 
773
 
                   (intbuff, 
774
 
                    "%02d:%02d:%02d", 
775
 
                    l_time->hour, 
776
 
                    l_time->minute,
777
 
                    l_time->second));
 
772
        length= sprintf(intbuff,  "%02d:%02d:%02d",
 
773
                        l_time->hour, l_time->minute, l_time->second);
778
774
        str->append(intbuff, length);
779
775
        break;
780
776
      case 'U':
822
818
      }
823
819
      break;
824
820
      case 'w':
825
 
        if (type == MYSQL_TIMESTAMP_TIME)
 
821
        if (type == MYSQL_TIMESTAMP_TIME || !(l_time->month || l_time->year))
826
822
          return 1;
827
823
        weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
828
824
                                        l_time->day),1);
1525
1521
    return 1;
1526
1522
  bzero(ltime, sizeof(MYSQL_TIME));
1527
1523
  get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
 
1524
 
 
1525
  if ((null_value= (fuzzy_date & TIME_NO_ZERO_DATE) &&
 
1526
       (ltime->year == 0 || ltime->month == 0 || ltime->day == 0)))
 
1527
    return TRUE;
 
1528
 
1528
1529
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
1529
1530
  return 0;
1530
1531
}
2276
2277
 
2277
2278
void Item_extract::fix_length_and_dec()
2278
2279
{
2279
 
  value.alloc(32);                              // alloc buffer
2280
 
 
2281
2280
  maybe_null=1;                                 // If wrong date
2282
2281
  switch (int_type) {
2283
2282
  case INTERVAL_YEAR:           max_length=4; date_value=1; break;
2320
2319
  }
2321
2320
  else
2322
2321
  {
 
2322
    char buf[40];
 
2323
    String value(buf, sizeof(buf), &my_charset_bin);;
2323
2324
    String *res= args[0]->val_str(&value);
2324
2325
    if (!res || str_to_time_with_warn(res->ptr(), res->length(), &ltime))
2325
2326
    {
2450
2451
  String *res;
2451
2452
  uint32 length;
2452
2453
 
 
2454
  if (cast_length >= 0 &&
 
2455
      ((unsigned) cast_length) > current_thd->variables.max_allowed_packet)
 
2456
  {
 
2457
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2458
                        ER_WARN_ALLOWED_PACKET_OVERFLOWED,
 
2459
                        ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
 
2460
                        cast_cs == &my_charset_bin ?
 
2461
                        "cast_as_binary" : func_name(),
 
2462
                        current_thd->variables.max_allowed_packet);
 
2463
    null_value= 1;
 
2464
    return 0;
 
2465
  }
 
2466
 
2453
2467
  if (!charset_conversion)
2454
2468
  {
2455
2469
    if (!(res= args[0]->val_str(str)))
2462
2476
  {
2463
2477
    // Convert character set if differ
2464
2478
    uint dummy_errors;
2465
 
    if (!(res= args[0]->val_str(&tmp_value)) ||
2466
 
        str->copy(res->ptr(), res->length(), from_cs,
2467
 
        cast_cs, &dummy_errors))
 
2479
    if (!(res= args[0]->val_str(str)) ||
 
2480
        tmp_value.copy(res->ptr(), res->length(), from_cs,
 
2481
                       cast_cs, &dummy_errors))
2468
2482
    {
2469
2483
      null_value= 1;
2470
2484
      return 0;
2471
2485
    }
2472
 
    res= str;
 
2486
    res= &tmp_value;
2473
2487
  }
2474
2488
 
2475
2489
  res->set_charset(cast_cs);
2503
2517
    {
2504
2518
      if (res->alloced_length() < (uint) cast_length)
2505
2519
      {
2506
 
        str->alloc(cast_length);
2507
 
        str->copy(*res);
2508
 
        res= str;
 
2520
        str_value.alloc(cast_length);
 
2521
        str_value.copy(*res);
 
2522
        res= &str_value;
2509
2523
      }
2510
2524
      bzero((char*) res->ptr() + res->length(),
2511
2525
            (uint) cast_length - res->length());
2632
2646
 
2633
2647
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
2634
2648
{
2635
 
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
 
2649
  bool res= get_arg0_date(ltime, fuzzy_date);
2636
2650
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2637
2651
  ltime->time_type= MYSQL_TIMESTAMP_DATE;
2638
2652
  return res;
2690
2704
  long days;
2691
2705
 
2692
2706
  if (args[0]->null_value || args[1]->null_value ||
2693
 
      year < 0 || daynr <= 0)
 
2707
      year < 0 || year > 9999 || daynr <= 0)
2694
2708
    goto err;
2695
2709
 
2696
2710
  if (year < 100)
2733
2747
  long days;
2734
2748
 
2735
2749
  if (args[0]->null_value || args[1]->null_value ||
2736
 
      year < 0 || daynr <= 0)
 
2750
      year < 0 || year > 9999 || daynr <= 0)
2737
2751
    goto err;
2738
2752
 
2739
2753
  if (year < 100)
2985
2999
    char buf[28];
2986
3000
    char *ptr= longlong10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2987
3001
    int len = (int)(ptr - buf) +
2988
 
      my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second));
 
3002
      sprintf(ptr, ":%02u:%02u", (uint) minute, (uint) second);
2989
3003
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2990
3004
                                 buf, len, MYSQL_TIMESTAMP_TIME,
2991
3005
                                 NullS);
2992
3006
  }
2993
 
  
 
3007
 
2994
3008
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
2995
3009
  {
2996
3010
    null_value= 1;
3299
3313
{
3300
3314
  maybe_null= 1;
3301
3315
  decimals=0;
 
3316
  cached_format_type= DATE_TIME;
3302
3317
  cached_field_type= MYSQL_TYPE_DATETIME;
3303
3318
  max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
3304
3319
  cached_timestamp_type= MYSQL_TIMESTAMP_NONE;