Commit 5382a182 authored by unknown's avatar unknown
Browse files

Merge bk-internal.mysql.com:/home/bk/mysql-4.1

into mysql.com:/media/sda1/mysql/mysql-4.1-6049

parents abb8268f 7c20b132
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -60,6 +60,20 @@ my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap)

void set_zero_time(MYSQL_TIME *tm);

/*
  Required buffer length for my_time_to_str, my_date_to_str,
  my_datetime_to_str and TIME_to_string functions. Note, that the
  caller is still responsible to check that given TIME structure
  has values in valid ranges, otherwise size of the buffer could
  be not enough.
*/
#define MAX_DATE_STRING_REP_LENGTH 30

int my_time_to_str(const MYSQL_TIME *l_time, char *to);
int my_date_to_str(const MYSQL_TIME *l_time, char *to);
int my_datetime_to_str(const MYSQL_TIME *l_time, char *to);
int my_TIME_to_str(const MYSQL_TIME *l_time, char *to);

C_MODE_END

#endif /* _my_time_h_ */
+5 −25
Original line number Diff line number Diff line
@@ -3231,12 +3231,12 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
    tm->second_part= (length > 8) ? (ulong) sint4korr(to+8) : 0;

    tm->year= tm->month= 0;
    tm->time_type= MYSQL_TIMESTAMP_TIME;

    *pos+= length;
  }
  else
    set_zero_time(tm);
  tm->time_type= MYSQL_TIMESTAMP_TIME;
}

static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
@@ -3261,12 +3261,12 @@ static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
    else
      tm->hour= tm->minute= tm->second= 0;
    tm->second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0;
    tm->time_type= MYSQL_TIMESTAMP_DATETIME;

    *pos+= length;
  }
  else
    set_zero_time(tm);
  tm->time_type= MYSQL_TIMESTAMP_DATETIME;
}

static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
@@ -3283,12 +3283,12 @@ static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
    tm->hour= tm->minute= tm->second= 0;
    tm->second_part= 0;
    tm->neg= 0;
    tm->time_type= MYSQL_TIMESTAMP_DATE;

    *pos+= length;
  }
  else
    set_zero_time(tm);
  tm->time_type= MYSQL_TIMESTAMP_DATE;
}


@@ -3566,28 +3566,8 @@ static void fetch_datetime_with_conversion(MYSQL_BIND *param,
      Convert time value  to string and delegate the rest to
      fetch_string_with_conversion:
    */
    char buff[25];
    uint length;

    switch (time->time_type) {
    case MYSQL_TIMESTAMP_DATE:
      length= my_sprintf(buff,(buff, "%04d-%02d-%02d",
                               time->year, time->month, time->day));
      break;
    case MYSQL_TIMESTAMP_DATETIME:
      length= my_sprintf(buff,(buff, "%04d-%02d-%02d %02d:%02d:%02d",
                               time->year, time->month, time->day,
                               time->hour, time->minute, time->second));
      break;
    case MYSQL_TIMESTAMP_TIME:
      length= my_sprintf(buff, (buff, "%02d:%02d:%02d",
                                time->hour, time->minute, time->second));
      break;
    default:
      length= 0;
      buff[0]='\0';
      break;
    }
    char buff[MAX_DATE_STRING_REP_LENGTH];
    uint length= my_TIME_to_str(time, buff);
    /* Resort to string conversion */
    fetch_string_with_conversion(param, (char *)buff, length);
    break;
+72 −0
Original line number Diff line number Diff line
@@ -726,3 +726,75 @@ void set_zero_time(MYSQL_TIME *tm)
  tm->time_type= MYSQL_TIMESTAMP_NONE;
}


/*
  Functions to convert time/date/datetime value to a string,
  using default format.
  This functions don't check that given TIME structure members are
  in valid range. If they are not, return value won't reflect any
  valid date either. Additionally, make_time doesn't take into
  account time->day member: it's assumed that days have been converted
  to hours already.

  RETURN
    number of characters written to 'to'
*/

int my_time_to_str(const MYSQL_TIME *l_time, char *to)
{
  return my_sprintf(to, (to, "%s%02d:%02d:%02d",
                         (l_time->neg ? "-" : ""),
                         l_time->hour,
                         l_time->minute,
                         l_time->second));
}

int my_date_to_str(const MYSQL_TIME *l_time, char *to)
{
  return my_sprintf(to, (to, "%04d-%02d-%02d",
                         l_time->year,
                         l_time->month,
                         l_time->day));
}

int my_datetime_to_str(const MYSQL_TIME *l_time, char *to)
{
  return my_sprintf(to, (to, "%04d-%02d-%02d %02d:%02d:%02d",
                         l_time->year,
                         l_time->month,
                         l_time->day,
                         l_time->hour,
                         l_time->minute,
                         l_time->second));
}


/*
  Convert struct DATE/TIME/DATETIME value to string using built-in
  MySQL time conversion formats.

  SYNOPSIS
    my_TIME_to_string()

  NOTE
    The string must have at least MAX_DATE_STRING_REP_LENGTH bytes reserved.
*/

int my_TIME_to_str(const MYSQL_TIME *l_time, char *to)
{
  switch (l_time->time_type) {
  case MYSQL_TIMESTAMP_DATETIME:
    return my_datetime_to_str(l_time, to);
  case MYSQL_TIMESTAMP_DATE:
    return my_date_to_str(l_time, to);
  case MYSQL_TIMESTAMP_TIME:
    return my_time_to_str(l_time, to);
  case MYSQL_TIMESTAMP_NONE:
  case MYSQL_TIMESTAMP_ERROR:
    to[0]='\0';
    return 0;
  default:
    DBUG_ASSERT(0);
    return 0;
  }
}
+3 −5
Original line number Diff line number Diff line
@@ -452,11 +452,9 @@ bool Field::get_time(TIME *ltime)

void Field::store_time(TIME *ltime,timestamp_type type)
{
  char buff[MAX_DATE_REP_LENGTH];
  String tmp;
  tmp.set(buff, sizeof(buff), &my_charset_bin);
  TIME_to_string(ltime, &tmp);
  store(buff, tmp.length(), &my_charset_bin);
  char buff[MAX_DATE_STRING_REP_LENGTH];
  uint length= (uint) my_TIME_to_str(ltime, buff);
  store(buff, length, &my_charset_bin);
}


+5 −9
Original line number Diff line number Diff line
@@ -988,9 +988,10 @@ String *Item_param::val_str(String* str)
    return str;
  case TIME_VALUE:
  {
    if (str->reserve(MAX_DATE_REP_LENGTH))
    if (str->reserve(MAX_DATE_STRING_REP_LENGTH))
      break;
    TIME_to_string(&value.time, str);
    str->length((uint) my_TIME_to_str(&value.time, (char*) str->ptr()));
    str->set_charset(&my_charset_bin);
    return str;
  }
  case NULL_VALUE:
@@ -1020,24 +1021,19 @@ const String *Item_param::query_val_str(String* str) const
  case TIME_VALUE:
    {
      char *buf, *ptr;
      String tmp;
      str->length(0);
      /*
        TODO: in case of error we need to notify replication
        that binary log contains wrong statement 
      */
      if (str->reserve(MAX_DATE_REP_LENGTH+3))
      if (str->reserve(MAX_DATE_STRING_REP_LENGTH+3))
        break; 

      /* Create date string inplace */
      buf= str->c_ptr_quick();
      ptr= buf;
      *ptr++= '\'';
      tmp.set(ptr, MAX_DATE_REP_LENGTH, &my_charset_bin);
      tmp.length(0);
      TIME_to_string(&value.time, &tmp);

      ptr+= tmp.length();
      ptr+= (uint) my_TIME_to_str(&value.time, ptr);
      *ptr++= '\'';
      str->length((uint32) (ptr - buf));
      break;
Loading