~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_timefunc.cc

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
286
286
  const char *ptr= format->format.str;
287
287
  const char *end= ptr + format->format.length;
288
288
  CHARSET_INFO *cs= &my_charset_bin;
289
 
  DBUG_ENTER("extract_date_time");
290
289
 
291
290
  if (!sub_pattern_end)
292
291
    bzero((char*) l_time, sizeof(*l_time));
465
464
        if (extract_date_time(&time_ampm_format, val,
466
465
                              (uint)(val_end - val), l_time,
467
466
                              cached_timestamp_type, &val, "time"))
468
 
          DBUG_RETURN(1);
 
467
          return(1);
469
468
        break;
470
469
 
471
470
        /* Time in 24-hour notation */
473
472
        if (extract_date_time(&time_24hrs_format, val,
474
473
                              (uint)(val_end - val), l_time,
475
474
                              cached_timestamp_type, &val, "time"))
476
 
          DBUG_RETURN(1);
 
475
          return(1);
477
476
        break;
478
477
 
479
478
        /* Conversion specifiers that match classes of characters */
516
515
  if (sub_pattern_end)
517
516
  {
518
517
    *sub_pattern_end= val;
519
 
    DBUG_RETURN(0);
 
518
    return(0);
520
519
  }
521
520
 
522
521
  if (yearday > 0)
590
589
      }
591
590
    } while (++val != val_end);
592
591
  }
593
 
  DBUG_RETURN(0);
 
592
  return(0);
594
593
 
595
594
err:
596
595
  {
600
599
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
601
600
                        date_time_type, buff, "str_to_date");
602
601
  }
603
 
  DBUG_RETURN(1);
 
602
  return(1);
604
603
}
605
604
 
606
605
 
898
897
 
899
898
longlong Item_func_period_add::val_int()
900
899
{
901
 
  DBUG_ASSERT(fixed == 1);
 
900
  assert(fixed == 1);
902
901
  ulong period=(ulong) args[0]->val_int();
903
902
  int months=(int) args[1]->val_int();
904
903
 
913
912
 
914
913
longlong Item_func_period_diff::val_int()
915
914
{
916
 
  DBUG_ASSERT(fixed == 1);
 
915
  assert(fixed == 1);
917
916
  ulong period1=(ulong) args[0]->val_int();
918
917
  ulong period2=(ulong) args[1]->val_int();
919
918
 
927
926
 
928
927
longlong Item_func_to_days::val_int()
929
928
{
930
 
  DBUG_ASSERT(fixed == 1);
 
929
  assert(fixed == 1);
931
930
  MYSQL_TIME ltime;
932
931
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
933
932
    return 0;
964
963
 
965
964
longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
966
965
{
967
 
  DBUG_ASSERT(fixed == 1);
 
966
  assert(fixed == 1);
968
967
  MYSQL_TIME ltime;
969
968
  longlong res;
970
969
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
995
994
                      ltime.second_part))
996
995
    ; /* do nothing */
997
996
  else
998
 
    *incl_endp= TRUE;
 
997
    *incl_endp= true;
999
998
  return res;
1000
999
}
1001
1000
 
1002
1001
 
1003
1002
longlong Item_func_dayofyear::val_int()
1004
1003
{
1005
 
  DBUG_ASSERT(fixed == 1);
 
1004
  assert(fixed == 1);
1006
1005
  MYSQL_TIME ltime;
1007
1006
  if (get_arg0_date(&ltime,TIME_NO_ZERO_DATE))
1008
1007
    return 0;
1012
1011
 
1013
1012
longlong Item_func_dayofmonth::val_int()
1014
1013
{
1015
 
  DBUG_ASSERT(fixed == 1);
 
1014
  assert(fixed == 1);
1016
1015
  MYSQL_TIME ltime;
1017
1016
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1018
1017
  return (longlong) ltime.day;
1020
1019
 
1021
1020
longlong Item_func_month::val_int()
1022
1021
{
1023
 
  DBUG_ASSERT(fixed == 1);
 
1022
  assert(fixed == 1);
1024
1023
  MYSQL_TIME ltime;
1025
1024
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1026
1025
  return (longlong) ltime.month;
1029
1028
 
1030
1029
String* Item_func_monthname::val_str(String* str)
1031
1030
{
1032
 
  DBUG_ASSERT(fixed == 1);
 
1031
  assert(fixed == 1);
1033
1032
  const char *month_name;
1034
1033
  uint   month= (uint) val_int();
1035
1034
  THD *thd= current_thd;
1052
1051
 
1053
1052
longlong Item_func_quarter::val_int()
1054
1053
{
1055
 
  DBUG_ASSERT(fixed == 1);
 
1054
  assert(fixed == 1);
1056
1055
  MYSQL_TIME ltime;
1057
1056
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1058
1057
    return 0;
1061
1060
 
1062
1061
longlong Item_func_hour::val_int()
1063
1062
{
1064
 
  DBUG_ASSERT(fixed == 1);
 
1063
  assert(fixed == 1);
1065
1064
  MYSQL_TIME ltime;
1066
1065
  (void) get_arg0_time(&ltime);
1067
1066
  return ltime.hour;
1069
1068
 
1070
1069
longlong Item_func_minute::val_int()
1071
1070
{
1072
 
  DBUG_ASSERT(fixed == 1);
 
1071
  assert(fixed == 1);
1073
1072
  MYSQL_TIME ltime;
1074
1073
  (void) get_arg0_time(&ltime);
1075
1074
  return ltime.minute;
1080
1079
*/
1081
1080
longlong Item_func_second::val_int()
1082
1081
{
1083
 
  DBUG_ASSERT(fixed == 1);
 
1082
  assert(fixed == 1);
1084
1083
  MYSQL_TIME ltime;
1085
1084
  (void) get_arg0_time(&ltime);
1086
1085
  return ltime.second;
1128
1127
 
1129
1128
longlong Item_func_week::val_int()
1130
1129
{
1131
 
  DBUG_ASSERT(fixed == 1);
 
1130
  assert(fixed == 1);
1132
1131
  uint year;
1133
1132
  MYSQL_TIME ltime;
1134
1133
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1141
1140
 
1142
1141
longlong Item_func_yearweek::val_int()
1143
1142
{
1144
 
  DBUG_ASSERT(fixed == 1);
 
1143
  assert(fixed == 1);
1145
1144
  uint year,week;
1146
1145
  MYSQL_TIME ltime;
1147
1146
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1155
1154
 
1156
1155
longlong Item_func_weekday::val_int()
1157
1156
{
1158
 
  DBUG_ASSERT(fixed == 1);
 
1157
  assert(fixed == 1);
1159
1158
  MYSQL_TIME ltime;
1160
1159
  
1161
1160
  if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
1169
1168
 
1170
1169
String* Item_func_dayname::val_str(String* str)
1171
1170
{
1172
 
  DBUG_ASSERT(fixed == 1);
 
1171
  assert(fixed == 1);
1173
1172
  uint weekday=(uint) val_int();                // Always Item_func_daynr()
1174
1173
  const char *day_name;
1175
1174
  THD *thd= current_thd;
1185
1184
 
1186
1185
longlong Item_func_year::val_int()
1187
1186
{
1188
 
  DBUG_ASSERT(fixed == 1);
 
1187
  assert(fixed == 1);
1189
1188
  MYSQL_TIME ltime;
1190
1189
  (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
1191
1190
  return (longlong) ltime.year;
1218
1217
 
1219
1218
longlong Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
1220
1219
{
1221
 
  DBUG_ASSERT(fixed == 1);
 
1220
  assert(fixed == 1);
1222
1221
  MYSQL_TIME ltime;
1223
1222
  if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
1224
1223
  {
1241
1240
      !(ltime.hour || ltime.minute || ltime.second || ltime.second_part))
1242
1241
    ; /* do nothing */
1243
1242
  else
1244
 
    *incl_endp= TRUE;
 
1243
    *incl_endp= true;
1245
1244
  return ltime.year;
1246
1245
}
1247
1246
 
1251
1250
  MYSQL_TIME ltime;
1252
1251
  bool not_used;
1253
1252
  
1254
 
  DBUG_ASSERT(fixed == 1);
 
1253
  assert(fixed == 1);
1255
1254
  if (arg_count == 0)
1256
1255
    return (longlong) current_thd->query_start();
1257
1256
  if (args[0]->type() == FIELD_ITEM)
1278
1277
 
1279
1278
longlong Item_func_time_to_sec::val_int()
1280
1279
{
1281
 
  DBUG_ASSERT(fixed == 1);
 
1280
  assert(fixed == 1);
1282
1281
  MYSQL_TIME ltime;
1283
1282
  longlong seconds;
1284
1283
  (void) get_arg0_time(&ltime);
1438
1437
    interval->second_part= array[1];
1439
1438
    break;
1440
1439
  case INTERVAL_LAST: /* purecov: begin deadcode */
1441
 
    DBUG_ASSERT(0); 
 
1440
    assert(0); 
1442
1441
    break;            /* purecov: end */
1443
1442
  }
1444
1443
  return 0;
1447
1446
 
1448
1447
String *Item_date::val_str(String *str)
1449
1448
{
1450
 
  DBUG_ASSERT(fixed == 1);
 
1449
  assert(fixed == 1);
1451
1450
  MYSQL_TIME ltime;
1452
1451
  if (get_date(&ltime, TIME_FUZZY_DATE))
1453
1452
    return (String *) 0;
1463
1462
 
1464
1463
longlong Item_date::val_int()
1465
1464
{
1466
 
  DBUG_ASSERT(fixed == 1);
 
1465
  assert(fixed == 1);
1467
1466
  MYSQL_TIME ltime;
1468
1467
  if (get_date(&ltime, TIME_FUZZY_DATE))
1469
1468
    return 0;
1499
1498
 
1500
1499
String *Item_func_curdate::val_str(String *str)
1501
1500
{
1502
 
  DBUG_ASSERT(fixed == 1);
 
1501
  assert(fixed == 1);
1503
1502
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
1504
1503
  {
1505
1504
    null_value= 1;
1547
1546
 
1548
1547
String *Item_func_curtime::val_str(String *str __attribute__((__unused__)))
1549
1548
{
1550
 
  DBUG_ASSERT(fixed == 1);
 
1549
  assert(fixed == 1);
1551
1550
  str_value.set(buff, buff_length, &my_charset_bin);
1552
1551
  return &str_value;
1553
1552
}
1596
1595
 
1597
1596
String *Item_func_now::val_str(String *str __attribute__((__unused__)))
1598
1597
{
1599
 
  DBUG_ASSERT(fixed == 1);
 
1598
  assert(fixed == 1);
1600
1599
  str_value.set(buff,buff_length, &my_charset_bin);
1601
1600
  return &str_value;
1602
1601
}
1672
1671
 
1673
1672
String *Item_func_sysdate_local::val_str(String *str __attribute__((__unused__)))
1674
1673
{
1675
 
  DBUG_ASSERT(fixed == 1);
 
1674
  assert(fixed == 1);
1676
1675
  store_now_in_TIME(&ltime);
1677
1676
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
1678
1677
  str_value.set(buff, buff_length, &my_charset_bin);
1682
1681
 
1683
1682
longlong Item_func_sysdate_local::val_int()
1684
1683
{
1685
 
  DBUG_ASSERT(fixed == 1);
 
1684
  assert(fixed == 1);
1686
1685
  store_now_in_TIME(&ltime);
1687
1686
  return (longlong) TIME_to_ulonglong_datetime(&ltime);
1688
1687
}
1690
1689
 
1691
1690
double Item_func_sysdate_local::val_real()
1692
1691
{
1693
 
  DBUG_ASSERT(fixed == 1);
 
1692
  assert(fixed == 1);
1694
1693
  store_now_in_TIME(&ltime);
1695
1694
  return ulonglong2double(TIME_to_ulonglong_datetime(&ltime));
1696
1695
}
1724
1723
 
1725
1724
String *Item_func_sec_to_time::val_str(String *str)
1726
1725
{
1727
 
  DBUG_ASSERT(fixed == 1);
 
1726
  assert(fixed == 1);
1728
1727
  MYSQL_TIME ltime;
1729
1728
  longlong arg_val= args[0]->val_int(); 
1730
1729
 
1744
1743
 
1745
1744
longlong Item_func_sec_to_time::val_int()
1746
1745
{
1747
 
  DBUG_ASSERT(fixed == 1);
 
1746
  assert(fixed == 1);
1748
1747
  MYSQL_TIME ltime;
1749
1748
  longlong arg_val= args[0]->val_int(); 
1750
1749
  
1893
1892
  String *format;
1894
1893
  MYSQL_TIME l_time;
1895
1894
  uint size;
1896
 
  DBUG_ASSERT(fixed == 1);
 
1895
  assert(fixed == 1);
1897
1896
 
1898
1897
  if (!is_time_format)
1899
1898
  {
1960
1959
{
1961
1960
  MYSQL_TIME time_tmp;
1962
1961
 
1963
 
  DBUG_ASSERT(fixed == 1);
 
1962
  assert(fixed == 1);
1964
1963
 
1965
1964
  if (get_date(&time_tmp, 0))
1966
1965
    return 0;
1981
1980
{
1982
1981
  MYSQL_TIME time_tmp;
1983
1982
 
1984
 
  DBUG_ASSERT(fixed == 1);
 
1983
  assert(fixed == 1);
1985
1984
 
1986
1985
  if (get_date(&time_tmp, 0))
1987
1986
    return 0;
2062
2061
 
2063
2062
String *Item_date_add_interval::val_str(String *str)
2064
2063
{
2065
 
  DBUG_ASSERT(fixed == 1);
 
2064
  assert(fixed == 1);
2066
2065
  MYSQL_TIME ltime;
2067
2066
  enum date_time_format_types format;
2068
2067
 
2086
2085
 
2087
2086
longlong Item_date_add_interval::val_int()
2088
2087
{
2089
 
  DBUG_ASSERT(fixed == 1);
 
2088
  assert(fixed == 1);
2090
2089
  MYSQL_TIME ltime;
2091
2090
  longlong date;
2092
2091
  if (Item_date_add_interval::get_date(&ltime, TIME_NO_ZERO_DATE))
2169
2168
  case INTERVAL_HOUR_MICROSECOND: max_length=13; date_value=0; break;
2170
2169
  case INTERVAL_MINUTE_MICROSECOND: max_length=11; date_value=0; break;
2171
2170
  case INTERVAL_SECOND_MICROSECOND: max_length=9; date_value=0; break;
2172
 
  case INTERVAL_LAST: DBUG_ASSERT(0); break; /* purecov: deadcode */
 
2171
  case INTERVAL_LAST: assert(0); break; /* purecov: deadcode */
2173
2172
  }
2174
2173
}
2175
2174
 
2176
2175
 
2177
2176
longlong Item_extract::val_int()
2178
2177
{
2179
 
  DBUG_ASSERT(fixed == 1);
 
2178
  assert(fixed == 1);
2180
2179
  MYSQL_TIME ltime;
2181
2180
  uint year;
2182
2181
  ulong week_format;
2239
2238
                                            ltime.second_part)*neg;
2240
2239
  case INTERVAL_SECOND_MICROSECOND: return ((longlong)ltime.second*1000000L+
2241
2240
                                            ltime.second_part)*neg;
2242
 
  case INTERVAL_LAST: DBUG_ASSERT(0); break;  /* purecov: deadcode */
 
2241
  case INTERVAL_LAST: assert(0); break;  /* purecov: deadcode */
2243
2242
  }
2244
2243
  return 0;                                     // Impossible
2245
2244
}
2315
2314
 
2316
2315
String *Item_char_typecast::val_str(String *str)
2317
2316
{
2318
 
  DBUG_ASSERT(fixed == 1);
 
2317
  assert(fixed == 1);
2319
2318
  String *res;
2320
2319
  uint32 length;
2321
2320
 
2427
2426
 
2428
2427
String *Item_datetime_typecast::val_str(String *str)
2429
2428
{
2430
 
  DBUG_ASSERT(fixed == 1);
 
2429
  assert(fixed == 1);
2431
2430
  MYSQL_TIME ltime;
2432
2431
 
2433
2432
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2442
2441
 
2443
2442
longlong Item_datetime_typecast::val_int()
2444
2443
{
2445
 
  DBUG_ASSERT(fixed == 1);
 
2444
  assert(fixed == 1);
2446
2445
  MYSQL_TIME ltime;
2447
2446
  if (get_arg0_date(&ltime,1))
2448
2447
  {
2481
2480
 
2482
2481
String *Item_time_typecast::val_str(String *str)
2483
2482
{
2484
 
  DBUG_ASSERT(fixed == 1);
 
2483
  assert(fixed == 1);
2485
2484
  MYSQL_TIME ltime;
2486
2485
 
2487
2486
  if (!get_arg0_time(&ltime) &&
2512
2511
 
2513
2512
String *Item_date_typecast::val_str(String *str)
2514
2513
{
2515
 
  DBUG_ASSERT(fixed == 1);
 
2514
  assert(fixed == 1);
2516
2515
  MYSQL_TIME ltime;
2517
2516
 
2518
2517
  if (!get_arg0_date(&ltime, TIME_FUZZY_DATE) &&
2528
2527
 
2529
2528
longlong Item_date_typecast::val_int()
2530
2529
{
2531
 
  DBUG_ASSERT(fixed == 1);
 
2530
  assert(fixed == 1);
2532
2531
  MYSQL_TIME ltime;
2533
2532
  if ((null_value= args[0]->get_date(&ltime, TIME_FUZZY_DATE)))
2534
2533
    return 0;
2547
2546
 
2548
2547
String *Item_func_makedate::val_str(String *str)
2549
2548
{
2550
 
  DBUG_ASSERT(fixed == 1);
 
2549
  assert(fixed == 1);
2551
2550
  MYSQL_TIME l_time;
2552
2551
  long daynr=  (long) args[1]->val_int();
2553
2552
  long year= (long) args[0]->val_int();
2590
2589
 
2591
2590
longlong Item_func_makedate::val_int()
2592
2591
{
2593
 
  DBUG_ASSERT(fixed == 1);
 
2592
  assert(fixed == 1);
2594
2593
  MYSQL_TIME l_time;
2595
2594
  long daynr=  (long) args[1]->val_int();
2596
2595
  long year= (long) args[0]->val_int();
2657
2656
 
2658
2657
String *Item_func_add_time::val_str(String *str)
2659
2658
{
2660
 
  DBUG_ASSERT(fixed == 1);
 
2659
  assert(fixed == 1);
2661
2660
  MYSQL_TIME l_time1, l_time2, l_time3;
2662
2661
  bool is_time= 0;
2663
2662
  long days, microseconds;
2730
2729
{
2731
2730
  if (is_date)
2732
2731
  {
2733
 
    DBUG_ASSERT(sign > 0);
 
2732
    assert(sign > 0);
2734
2733
    str->append(STRING_WITH_LEN("timestamp("));
2735
2734
  }
2736
2735
  else
2757
2756
 
2758
2757
String *Item_func_timediff::val_str(String *str)
2759
2758
{
2760
 
  DBUG_ASSERT(fixed == 1);
 
2759
  assert(fixed == 1);
2761
2760
  longlong seconds;
2762
2761
  long microseconds;
2763
2762
  int l_sign= 1;
2805
2804
 
2806
2805
String *Item_func_maketime::val_str(String *str)
2807
2806
{
2808
 
  DBUG_ASSERT(fixed == 1);
 
2807
  assert(fixed == 1);
2809
2808
  MYSQL_TIME ltime;
2810
2809
  bool overflow= 0;
2811
2810
 
2874
2873
 
2875
2874
longlong Item_func_microsecond::val_int()
2876
2875
{
2877
 
  DBUG_ASSERT(fixed == 1);
 
2876
  assert(fixed == 1);
2878
2877
  MYSQL_TIME ltime;
2879
2878
  if (!get_arg0_time(&ltime))
2880
2879
    return ltime.second_part;
3035
3034
 
3036
3035
String *Item_func_get_format::val_str(String *str)
3037
3036
{
3038
 
  DBUG_ASSERT(fixed == 1);
 
3037
  assert(fixed == 1);
3039
3038
  const char *format_name;
3040
3039
  KNOWN_DATE_TIME_FORMAT *format;
3041
3040
  String *val= args[0]->val_str(str);
3083
3082
    str->append(STRING_WITH_LEN("TIME, "));
3084
3083
    break;
3085
3084
  default:
3086
 
    DBUG_ASSERT(0);
 
3085
    assert(0);
3087
3086
  }
3088
3087
  args[0]->print(str, query_type);
3089
3088
  str->append(')');
3237
3236
 
3238
3237
String *Item_func_str_to_date::val_str(String *str)
3239
3238
{
3240
 
  DBUG_ASSERT(fixed == 1);
 
3239
  assert(fixed == 1);
3241
3240
  MYSQL_TIME ltime;
3242
3241
 
3243
3242
  if (Item_func_str_to_date::get_date(&ltime, TIME_FUZZY_DATE))