diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index f2ec17c5..966bd42b 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -847,21 +847,27 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, break; case MYSQL_TYPE_TIME: length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second); - if (tm.second_part) + if (field->decimals) { - char helper[16]; - sprintf(helper, ".%%0%du", field->decimals); - length+= sprintf(dtbuffer + length, helper, tm.second_part); + char ms[8]; + sprintf(ms, ".%06u", tm.second_part); + if (field->decimals < 6) + ms[field->decimals + 1]= 0; + length+= strlen(ms); + strcat(dtbuffer, ms); } break; case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second); - if (tm.second_part) + if (field->decimals) { - char helper[16]; - sprintf(helper, ".%%0%du", field->decimals); - length+= sprintf(dtbuffer + length, helper, tm.second_part); + char ms[8]; + sprintf(ms, ".%06u", tm.second_part); + if (field->decimals < 6) + ms[field->decimals + 1]= 0; + length+= strlen(ms); + strcat(dtbuffer, ms); } break; default: diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index 8583e8c4..98a349ef 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -231,8 +231,6 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) } } } - - current->length= packet_len; result->rows++; } else /* end of stream */ diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index d786bd6c..bea9dbee 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -4053,7 +4053,53 @@ static int test_conc155(MYSQL *mysql) return OK; } +static int test_conc168(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + + MYSQL_BIND bind; + char buffer[100]; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc168"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc168(a datetime(3))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO conc168 VALUES ('2016-03-09 07:51:49.000'),('2016-03-09 07:51:49.001'),('2016-03-09 07:51:49.010')"); + check_mysql_rc(rc, mysql); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer= buffer; + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer_length= 100; + + rc= mysql_stmt_prepare(stmt, "SELECT a FROM conc168", strlen("SELECT a FROM conc168")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.000"), "expected: 2016-03-09 07:51:49.000"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.001"), "expected: 2016-03-09 07:51:49.001"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.010"), "expected: 2016-03-09 07:51:49.010"); + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc168", test_conc168, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc155", test_conc155, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc154", test_conc154, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, {"test_conc141", test_conc141, TEST_CONNECTION_NEW, 0, NULL , NULL},