1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

CONC-371 fix for frac > 6

This commit is contained in:
Sergei Golubchik
2018-11-07 13:29:43 +01:00
parent efc9f60dbf
commit 6545b1d194
2 changed files with 6 additions and 4 deletions

View File

@@ -255,7 +255,7 @@ my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm)
if ((frac= strchr(start, '.'))) /* fractional seconds */ if ((frac= strchr(start, '.'))) /* fractional seconds */
{ {
size_t frac_len= (begin + length) - (frac + 1); size_t frac_len= (begin + length) - (frac + 1);
if (sscanf(start, "%d:%d:%d.%ld", &tm->hour, &tm->minute, if (sscanf(start, "%d:%d:%d.%6ld", &tm->hour, &tm->minute,
&tm->second,&tm->second_part) < 4) &tm->second,&tm->second_part) < 4)
goto error; goto error;
/* conc-371 */ /* conc-371 */

View File

@@ -4792,11 +4792,12 @@ static int test_conc_fraction(MYSQL *mysql)
int i; int i;
MYSQL_STMT *stmt= mysql_stmt_init(mysql); MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc; int rc;
unsigned long frac= 0;
for (i=0; i < 6; i++) for (i=0; i < 10; i++, frac=frac*10+i)
{ {
unsigned long expected= 0; unsigned long expected= 0;
sprintf(query, "SELECT '2018-11-05 22:25:59.%0*d'", i + 1, 9); sprintf(query, "SELECT '2018-11-05 22:25:59.%ld'", frac);
diag("%d: %s", i, query); diag("%d: %s", i, query);
@@ -4821,8 +4822,9 @@ static int test_conc_fraction(MYSQL *mysql)
diag("second_part: %ld", tm.second_part); diag("second_part: %ld", tm.second_part);
expected= 9 * (unsigned int)powl(10, (5 - i)); expected= i > 6 ? 123456 : frac * (unsigned int)powl(10, (6 - i));
diag("tm.second_part=%ld expected=%ld", tm.second_part, expected);
FAIL_IF(tm.second_part != expected, "expected fractional part to be 900000"); FAIL_IF(tm.second_part != expected, "expected fractional part to be 900000");
} }