diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index 1ee343e90..21649c2d0 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -582,7 +582,7 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h *(*f)->null_ptr &= ~(*f)->null_bit; intColVal = row.getUintField<8>(s); - DataConvert::datetimeToString(intColVal, tmp, 255); + DataConvert::datetimeToString(intColVal, tmp, 255, colType.precision); /* setting the field_length is a sort-of hack. The length * at this point can be long enough to include mseconds. @@ -606,7 +606,7 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h *(*f)->null_ptr &= ~(*f)->null_bit; intColVal = row.getUintField<8>(s); - DataConvert::timeToString(intColVal, tmp, 255); + DataConvert::timeToString(intColVal, tmp, 255, colType.precision); Field_varstring* f2 = (Field_varstring*)*f; f2->store(tmp, strlen(tmp), f2->charset()); diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index 7b92f36b0..398622631 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -2082,13 +2082,8 @@ std::string DataConvert::datetimeToString( long long datetimevalue, long decima if (dt.msecond && decimals) { - snprintf(buf + strlen(buf), 21 + decimals, ".%d", dt.msecond); - - // Pad end with zeros - if (strlen(buf) < (size_t)(21 + decimals)) - { - sprintf(buf + strlen(buf), "%0*d", (int)(21 + decimals - strlen(buf)), 0); - } + // Pad start with zeros + sprintf(buf + strlen(buf), ".%0*d", (int)decimals, dt.msecond); } return buf; @@ -2118,14 +2113,8 @@ std::string DataConvert::timeToString( long long timevalue, long decimals ) if (dt.msecond && decimals) { - size_t start = strlen(buf); - snprintf(buf + strlen(buf), 12 + decimals, ".%d", dt.msecond); - - // Pad end with zeros - if (strlen(buf) - start < (size_t)decimals) - { - sprintf(buf + strlen(buf), "%0*d", (int)(decimals - (strlen(buf) - start) + 1), 0); - } + // Pad start with zeros + sprintf(buf + strlen(buf), ".%0*d", (int)decimals, dt.msecond); } return buf; diff --git a/utils/dataconvert/dataconvert.h b/utils/dataconvert/dataconvert.h index 0cf3480c5..c01f261b6 100644 --- a/utils/dataconvert/dataconvert.h +++ b/utils/dataconvert/dataconvert.h @@ -587,14 +587,7 @@ inline void DataConvert::datetimeToString( long long datetimevalue, char* buf, u if (msec || decimals) { - size_t start = strlen(buf); - snprintf(buf + strlen(buf), buflen - start, ".%d", msec); - - // Pad end with zeros - if (strlen(buf) - start < (size_t)decimals) - { - snprintf(buf + strlen(buf), buflen - strlen(buf), "%0*d", (int)(decimals - (strlen(buf) - start) + 1), 0); - } + snprintf(buf + strlen(buf), buflen - strlen(buf), ".%0*d", (int)decimals, msec); } } @@ -636,14 +629,8 @@ inline void DataConvert::timeToString( long long timevalue, char* buf, unsigned if (msec || decimals) { - size_t start = strlen(buf); - snprintf(buf + strlen(buf), buflen - start, ".%d", msec); - - // Pad end with zeros - if (strlen(buf) - start < (size_t)decimals) - { - snprintf(buf + strlen(buf), buflen - strlen(buf), "%0*d", (int)(decimals - (strlen(buf) - start) + 1), 0); - } + // Pad start with zeros + snprintf(buf + strlen(buf), buflen - strlen(buf), ".%0*d", (int)decimals, msec); } }