1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

MCOL-1427 Fix microsecond padding for display

We were padding from right, we needed to pad from left.
This commit is contained in:
Andrew Hutchings
2018-06-04 19:57:42 +01:00
parent 51afdc98fc
commit 6948ab85a3
3 changed files with 9 additions and 33 deletions

View File

@ -582,7 +582,7 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h
*(*f)->null_ptr &= ~(*f)->null_bit; *(*f)->null_ptr &= ~(*f)->null_bit;
intColVal = row.getUintField<8>(s); 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 /* setting the field_length is a sort-of hack. The length
* at this point can be long enough to include mseconds. * 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; *(*f)->null_ptr &= ~(*f)->null_bit;
intColVal = row.getUintField<8>(s); intColVal = row.getUintField<8>(s);
DataConvert::timeToString(intColVal, tmp, 255); DataConvert::timeToString(intColVal, tmp, 255, colType.precision);
Field_varstring* f2 = (Field_varstring*)*f; Field_varstring* f2 = (Field_varstring*)*f;
f2->store(tmp, strlen(tmp), f2->charset()); f2->store(tmp, strlen(tmp), f2->charset());

View File

@ -2082,13 +2082,8 @@ std::string DataConvert::datetimeToString( long long datetimevalue, long decima
if (dt.msecond && decimals) if (dt.msecond && decimals)
{ {
snprintf(buf + strlen(buf), 21 + decimals, ".%d", dt.msecond); // Pad start with zeros
sprintf(buf + strlen(buf), ".%0*d", (int)decimals, 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);
}
} }
return buf; return buf;
@ -2118,14 +2113,8 @@ std::string DataConvert::timeToString( long long timevalue, long decimals )
if (dt.msecond && decimals) if (dt.msecond && decimals)
{ {
size_t start = strlen(buf); // Pad start with zeros
snprintf(buf + strlen(buf), 12 + decimals, ".%d", dt.msecond); sprintf(buf + strlen(buf), ".%0*d", (int)decimals, 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);
}
} }
return buf; return buf;

View File

@ -587,14 +587,7 @@ inline void DataConvert::datetimeToString( long long datetimevalue, char* buf, u
if (msec || decimals) if (msec || decimals)
{ {
size_t start = strlen(buf); snprintf(buf + strlen(buf), buflen - strlen(buf), ".%0*d", (int)decimals, msec);
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);
}
} }
} }
@ -636,14 +629,8 @@ inline void DataConvert::timeToString( long long timevalue, char* buf, unsigned
if (msec || decimals) if (msec || decimals)
{ {
size_t start = strlen(buf); // Pad start with zeros
snprintf(buf + strlen(buf), buflen - start, ".%d", msec); snprintf(buf + strlen(buf), buflen - strlen(buf), ".%0*d", (int)decimals, 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);
}
} }
} }