~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_timefunc.cc

Merging from trunk r102

Show diffs side-by-side

added added

removed removed

Lines of Context:
872
872
    longlong value;
873
873
    const char *start= str;
874
874
    for (value=0; str != end && my_isdigit(cs,*str) ; str++)
875
 
      value= value*LL(10) + (longlong) (*str - '0');
 
875
      value= value * 10LL + (longlong) (*str - '0');
876
876
    if (transform_msec && i == count - 1) // microseconds always last
877
877
    {
878
878
      long msec_length= 6 - (str - start);
953
953
{
954
954
  if (args[0]->type() == Item::FIELD_ITEM)
955
955
  {
956
 
    if (args[0]->field_type() == MYSQL_TYPE_DATE)
 
956
    if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
957
957
      return MONOTONIC_STRICT_INCREASING;
958
958
    if (args[0]->field_type() == MYSQL_TYPE_DATETIME)
959
959
      return MONOTONIC_INCREASING;
974
974
  }
975
975
  res=(longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
976
976
  
977
 
  if (args[0]->field_type() == MYSQL_TYPE_DATE)
 
977
  if (args[0]->field_type() == MYSQL_TYPE_NEWDATE)
978
978
  {
979
979
    // TO_DAYS() is strictly monotonic for dates, leave incl_endp intact
980
980
    return res;
1209
1209
enum_monotonicity_info Item_func_year::get_monotonicity_info() const
1210
1210
{
1211
1211
  if (args[0]->type() == Item::FIELD_ITEM &&
1212
 
      (args[0]->field_type() == MYSQL_TYPE_DATE ||
 
1212
      (args[0]->field_type() == MYSQL_TYPE_NEWDATE ||
1213
1213
       args[0]->field_type() == MYSQL_TYPE_DATETIME))
1214
1214
    return MONOTONIC_INCREASING;
1215
1215
  return NON_MONOTONIC;
1249
1249
longlong Item_func_unix_timestamp::val_int()
1250
1250
{
1251
1251
  MYSQL_TIME ltime;
1252
 
  my_bool not_used;
 
1252
  bool not_used;
1253
1253
  
1254
1254
  DBUG_ASSERT(fixed == 1);
1255
1255
  if (arg_count == 0)
1471
1471
}
1472
1472
 
1473
1473
 
1474
 
bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
 
1474
bool Item_func_from_days::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
1475
1475
{
1476
1476
  longlong value=args[0]->val_int();
1477
1477
  if ((null_value=args[0]->null_value))
1545
1545
}
1546
1546
 
1547
1547
 
1548
 
String *Item_func_curtime::val_str(String *str)
 
1548
String *Item_func_curtime::val_str(String *str __attribute__((__unused__)))
1549
1549
{
1550
1550
  DBUG_ASSERT(fixed == 1);
1551
1551
  str_value.set(buff, buff_length, &my_charset_bin);
1594
1594
}
1595
1595
 
1596
1596
 
1597
 
String *Item_func_now::val_str(String *str)
 
1597
String *Item_func_now::val_str(String *str __attribute__((__unused__)))
1598
1598
{
1599
1599
  DBUG_ASSERT(fixed == 1);
1600
1600
  str_value.set(buff,buff_length, &my_charset_bin);
1651
1651
}
1652
1652
 
1653
1653
 
1654
 
int Item_func_now::save_in_field(Field *to, bool no_conversions)
 
1654
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1655
1655
{
1656
1656
  to->set_notnull();
1657
1657
  return to->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
1670
1670
}
1671
1671
 
1672
1672
 
1673
 
String *Item_func_sysdate_local::val_str(String *str)
 
1673
String *Item_func_sysdate_local::val_str(String *str __attribute__((__unused__)))
1674
1674
{
1675
1675
  DBUG_ASSERT(fixed == 1);
1676
1676
  store_now_in_TIME(&ltime);
1713
1713
}
1714
1714
 
1715
1715
 
1716
 
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions)
 
1716
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((__unused__)))
1717
1717
{
1718
1718
  store_now_in_TIME(&ltime);
1719
1719
  to->set_notnull();
2020
2020
    follows:
2021
2021
 
2022
2022
    - If first arg is a MYSQL_TYPE_DATETIME result is MYSQL_TYPE_DATETIME
2023
 
    - If first arg is a MYSQL_TYPE_DATE and the interval type uses hours,
 
2023
    - If first arg is a MYSQL_TYPE_NEWDATE and the interval type uses hours,
2024
2024
      minutes or seconds then type is MYSQL_TYPE_DATETIME.
2025
2025
    - Otherwise the result is MYSQL_TYPE_STRING
2026
2026
      (This is because you can't know if the string contains a DATE, MYSQL_TIME or
2031
2031
  if (arg0_field_type == MYSQL_TYPE_DATETIME ||
2032
2032
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
2033
2033
    cached_field_type= MYSQL_TYPE_DATETIME;
2034
 
  else if (arg0_field_type == MYSQL_TYPE_DATE)
 
2034
  else if (arg0_field_type == MYSQL_TYPE_NEWDATE)
2035
2035
  {
2036
2036
    if (int_type <= INTERVAL_DAY || int_type == INTERVAL_YEAR_MONTH)
2037
2037
      cached_field_type= arg0_field_type;
2043
2043
 
2044
2044
/* Here arg[1] is a Item_interval object */
2045
2045
 
2046
 
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
 
2046
bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2047
2047
{
2048
2048
  INTERVAL interval;
2049
2049
 
2353
2353
    if (res->length() > (length= (uint32) res->charpos(cast_length)))
2354
2354
    {                                           // Safe even if const arg
2355
2355
      char char_type[40];
2356
 
      my_snprintf(char_type, sizeof(char_type), "%s(%lu)",
2357
 
                  cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
2358
 
                  (ulong) length);
 
2356
      snprintf(char_type, sizeof(char_type), "%s(%lu)",
 
2357
               cast_cs == &my_charset_bin ? "BINARY" : "CHAR",
 
2358
               (ulong) length);
2359
2359
 
2360
2360
      if (!res->alloced_length())
2361
2361
      {                                         // Don't change const str
2494
2494
}
2495
2495
 
2496
2496
 
2497
 
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
 
2497
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date __attribute__((__unused__)))
2498
2498
{
2499
2499
  bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
2500
2500
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
2637
2637
 
2638
2638
  cached_field_type= MYSQL_TYPE_STRING;
2639
2639
  arg0_field_type= args[0]->field_type();
2640
 
  if (arg0_field_type == MYSQL_TYPE_DATE ||
 
2640
  if (arg0_field_type == MYSQL_TYPE_NEWDATE ||
2641
2641
      arg0_field_type == MYSQL_TYPE_DATETIME ||
2642
2642
      arg0_field_type == MYSQL_TYPE_TIMESTAMP)
2643
2643
    cached_field_type= MYSQL_TYPE_DATETIME;
3178
3178
      switch (cached_format_type) {
3179
3179
      case DATE_ONLY:
3180
3180
        cached_timestamp_type= MYSQL_TIMESTAMP_DATE;
3181
 
        cached_field_type= MYSQL_TYPE_DATE; 
 
3181
        cached_field_type= MYSQL_TYPE_NEWDATE; 
3182
3182
        max_length= MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
3183
3183
        break;
3184
3184
      case TIME_ONLY: