Skip to content

Commit a9fa9ee

Browse files
author
Hemant Dangi
committed
Bug#68523: ResultSet::getString does not return fractional seconds from DATETIME(N) columns
1 parent de1eeaf commit a9fa9ee

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ GA 1.1.6 -
3434
- wasNull() method call before fetching the data results in assert failure
3535
(Bug#19938873)
3636
- Memory leak if result set of prepared statement used (Bug#18135088/wl#7925)
37+
- ResultSet::getString does not return fractional seconds from DATETIME(N)
38+
columns (Bug#68523)
3739

3840
GA 1.1.5 -
3941
- DatabaseMetaData::getProcedures() returns syntax error for connection option

driver/mysql_ps_resultset.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,15 @@ MySQL_Prepared_ResultSet::getString(const uint32_t columnIndex) const
955955
switch (rs_meta->getColumnType(columnIndex)) {
956956
case sql::DataType::TIMESTAMP:
957957
{
958-
char buf[22];
958+
char buf[28];
959959
MYSQL_TIME * t = static_cast<MYSQL_TIME *>(result_bind->rbind[columnIndex - 1].buffer);
960-
snprintf(buf, sizeof(buf) - 1, "%04d-%02d-%02d %02d:%02d:%02d", t->year, t->month, t->day, t->hour, t->minute, t->second);
960+
if (t->second_part) {
961+
snprintf(buf, sizeof(buf) - 1, "%04d-%02d-%02d %02d:%02d:%02d.%06lu",
962+
t->year, t->month, t->day, t->hour, t->minute, t->second, t->second_part);
963+
} else {
964+
snprintf(buf, sizeof(buf) - 1, "%04d-%02d-%02d %02d:%02d:%02d",
965+
t->year, t->month, t->day, t->hour, t->minute, t->second);
966+
}
961967
CPP_INFO_FMT("It's a datetime/timestamp %s", buf);
962968
return sql::SQLString(buf);
963969
}
@@ -971,9 +977,13 @@ MySQL_Prepared_ResultSet::getString(const uint32_t columnIndex) const
971977
}
972978
case sql::DataType::TIME:
973979
{
974-
char buf[12];
980+
char buf[18];
975981
MYSQL_TIME * t = static_cast<MYSQL_TIME *>(result_bind->rbind[columnIndex - 1].buffer);
976-
snprintf(buf, sizeof(buf) - 1, "%s%02d:%02d:%02d", t->neg? "-":"", t->hour, t->minute, t->second);
982+
if (t->second_part) {
983+
snprintf(buf, sizeof(buf) - 1, "%s%02d:%02d:%02d.%06lu", t->neg? "-":"", t->hour, t->minute, t->second, t->second_part);
984+
} else {
985+
snprintf(buf, sizeof(buf) - 1, "%s%02d:%02d:%02d", t->neg? "-":"", t->hour, t->minute, t->second);
986+
}
977987
CPP_INFO_FMT("It's a time %s", buf);
978988
return sql::SQLString(buf);
979989
}

test/unit/bugs/bugs.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,32 @@ void bugs::bug19938873_stmt()
660660
}
661661

662662

663+
void bugs::bug68523()
664+
{
665+
try
666+
{
667+
stmt->execute("DROP TABLE IF EXISTS bug68523");
668+
stmt->execute("CREATE TABLE bug68523(ts TIMESTAMP(6))");
669+
stmt->execute("INSERT INTO bug68523(ts) values('2015-01-20 16:14:36.709649')");
670+
671+
pstmt.reset(con->prepareStatement("SELECT ts, TIME(ts) from bug68523"));
672+
res.reset(pstmt->executeQuery());
673+
ASSERT(res->next());
674+
675+
ASSERT_EQUALS(res->getString(1), "2015-01-20 16:14:36.709649");
676+
ASSERT_EQUALS(res->getString(2), "16:14:36.709649");
677+
678+
stmt->execute("DROP TABLE IF EXISTS bug68523");
679+
}
680+
catch (sql::SQLException &e)
681+
{
682+
logErr(e.what());
683+
logErr("SQLState: " + std::string(e.getSQLState()));
684+
fail(e.what(), __FILE__, __LINE__);
685+
}
686+
687+
}
688+
689+
663690
} /* namespace regression */
664691
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class bugs : public unit_fixture
5959
TEST_CASE(bug20085944);
6060
TEST_CASE(bug19938873_pstmt);
6161
TEST_CASE(bug19938873_stmt);
62+
TEST_CASE(bug68523);
6263
}
6364

6465
/**
@@ -98,6 +99,7 @@ class bugs : public unit_fixture
9899

99100
void bug19938873_stmt();
100101

102+
void bug68523();
101103
};
102104

103105
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)