Loading include/my_time.h +14 −0 Original line number Diff line number Diff line Loading @@ -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_ */ libmysql/libmysql.c +5 −25 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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) Loading @@ -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; } Loading Loading @@ -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; Loading ndb/src/ndbapi/NdbOperationSearch.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -543,7 +543,8 @@ NdbOperation::getKeyFromTCREQ(Uint32* data, unsigned size) assert(m_accessTable->m_sizeOfKeysInWords == size); unsigned pos = 0; while (pos < 8 && pos < size) { data[pos++] = theKEYINFOptr[pos]; data[pos] = theKEYINFOptr[pos]; pos++; } NdbApiSignal* tSignal = theFirstKEYINFO; unsigned n = 0; Loading sql-common/my_time.c +72 −0 Original line number Diff line number Diff line Loading @@ -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; } } sql/field.cc +3 −5 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading
include/my_time.h +14 −0 Original line number Diff line number Diff line Loading @@ -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_ */
libmysql/libmysql.c +5 −25 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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) Loading @@ -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; } Loading Loading @@ -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; Loading
ndb/src/ndbapi/NdbOperationSearch.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -543,7 +543,8 @@ NdbOperation::getKeyFromTCREQ(Uint32* data, unsigned size) assert(m_accessTable->m_sizeOfKeysInWords == size); unsigned pos = 0; while (pos < 8 && pos < size) { data[pos++] = theKEYINFOptr[pos]; data[pos] = theKEYINFOptr[pos]; pos++; } NdbApiSignal* tSignal = theFirstKEYINFO; unsigned n = 0; Loading
sql-common/my_time.c +72 −0 Original line number Diff line number Diff line Loading @@ -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; } }
sql/field.cc +3 −5 Original line number Diff line number Diff line Loading @@ -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); } Loading