Skip to content

Commit cf51692

Browse files
author
Hemant Dangi
committed
Bug#66235: MySQL_ResultSet::getString() returns bad value for BIT data
1 parent 28d1489 commit cf51692

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ GA 1.1.6 -
3737
- ResultSet::getString does not return fractional seconds from DATETIME(N)
3838
columns (Bug#68523)
3939
- make install/fast fails if static library is not built (Bug#52281)
40+
- MySQL_ResultSet::getString() returns bad value for BIT data (Bug#66235)
4041

4142
GA 1.1.5 -
4243
- DatabaseMetaData::getProcedures() returns syntax error for connection option

driver/mysql_resultset.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -500,7 +500,8 @@ MySQL_ResultSet::getInt64(const uint32_t columnIndex) const
500500
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
501501
was_null = false;
502502
last_queried_column = columnIndex;
503-
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT) {
503+
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
504+
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
504505
uint64_t uval = 0;
505506
std::div_t length= std::div(getFieldMeta(columnIndex)->length, 8);
506507
if (length.rem) {
@@ -560,12 +561,14 @@ MySQL_ResultSet::getUInt64(const uint32_t columnIndex) const
560561
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
561562
was_null = false;
562563
last_queried_column = columnIndex;
563-
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT) {
564+
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
565+
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
564566
uint64_t uval = 0;
565567
std::div_t length= std::div(getFieldMeta(columnIndex)->length, 8);
566568
if (length.rem) {
567569
++length.quot;
568570
}
571+
569572
switch (length.quot) {
570573
case 8:uval = (uint64_t) bit_uint8korr(row[columnIndex - 1]);break;
571574
case 7:uval = (uint64_t) bit_uint7korr(row[columnIndex - 1]);break;

test/unit/bugs/bugs.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -262,6 +262,7 @@ void bugs::supportIssue_52319()
262262
/* Bug#15936764/67325 */
263263
void bugs::expired_pwd()
264264
{
265+
logMsg("bugs::expired_pwd");
265266
if (getMySQLVersion(con) < 56006)
266267
{
267268
SKIP("The server does not support tested functionality(expired password)");
@@ -386,6 +387,7 @@ void bugs::expired_pwd()
386387
*/
387388
void bugs::legacy_auth()
388389
{
390+
logMsg("bugs::legacy_auth");
389391
try
390392
{
391393
stmt->executeUpdate("DROP USER ccpp_legacy_auth");
@@ -475,6 +477,7 @@ void bugs::legacy_auth()
475477
/* Bug #18193771/71605 - The driver does not recognize utf8mb4 charset */
476478
void bugs::bug71606()
477479
{
480+
logMsg("bugs::bug71606");
478481
if (getMySQLVersion(con) < 56000)
479482
{
480483
SKIP("The server does not support tested functionality(utf8mb4 charset)");
@@ -517,6 +520,7 @@ void bugs::bug71606()
517520

518521
void bugs::bug72700()
519522
{
523+
logMsg("bugs::bug72700");
520524
ASSERT(stmt->execute("select astext(geomfromtext('point(10 10)'))"));
521525

522526
try
@@ -558,6 +562,7 @@ void bugs::bug66871()
558562
sql::Statement *stmt;
559563
sql::ResultSet *res;
560564

565+
logMsg("bugs::bug66871");
561566
try
562567
{
563568
con = getConnection(NULL);
@@ -589,6 +594,7 @@ void bugs::bug66871()
589594
*/
590595
void bugs::bug20085944()
591596
{
597+
logMsg("bugs::bug20085944");
592598
try
593599
{
594600
sql::ConnectOptionsMap connection_properties;
@@ -626,6 +632,7 @@ void bugs::bug20085944()
626632

627633
void bugs::bug19938873_pstmt()
628634
{
635+
logMsg("bugs::bug19938873_pstmt");
629636
try
630637
{
631638
pstmt.reset(con->prepareStatement("SELECT NULL"));
@@ -644,6 +651,7 @@ void bugs::bug19938873_pstmt()
644651

645652
void bugs::bug19938873_stmt()
646653
{
654+
logMsg("bugs::bug19938873_stmt");
647655
try
648656
{
649657
stmt.reset(con->createStatement());
@@ -687,5 +695,43 @@ void bugs::bug68523()
687695
}
688696

689697

698+
void bugs::bug66235()
699+
{
700+
logMsg("bug::bug66235");
701+
try
702+
{
703+
stmt.reset(con->createStatement());
704+
stmt->execute("DROP TABLE IF EXISTS test");
705+
stmt->execute("CREATE TABLE test(id BIT(3))");
706+
stmt->execute("INSERT INTO test(id) VALUES(1), (10), (1), (1), (10), (111);");
707+
708+
res.reset(stmt->executeQuery("SELECT MAX(id), MIN(id) FROM test"));
709+
while (res->next())
710+
{
711+
ASSERT_EQUALS(res->getString(1), "7");
712+
ASSERT_EQUALS(res->getInt(1), 7);
713+
714+
ASSERT_EQUALS(res->getString(2), "1");
715+
ASSERT_EQUALS(res->getInt(2), 1);
716+
}
717+
718+
res.reset(stmt->executeQuery("SELECT id FROM test limit 1"));
719+
while (res->next())
720+
{
721+
ASSERT_EQUALS(res->getString(1), "1");
722+
ASSERT_EQUALS(res->getInt(1), 1);
723+
}
724+
725+
stmt->execute("DROP TABLE IF EXISTS test");
726+
}
727+
catch (sql::SQLException &e)
728+
{
729+
logErr(e.what());
730+
logErr("SQLState: " + std::string(e.getSQLState()));
731+
fail(e.what(), __FILE__, __LINE__);
732+
}
733+
}
734+
735+
690736
} /* namespace regression */
691737
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class bugs : public unit_fixture
6060
TEST_CASE(bug19938873_pstmt);
6161
TEST_CASE(bug19938873_stmt);
6262
TEST_CASE(bug68523);
63+
TEST_CASE(bug66235);
6364
}
6465

6566
/**
@@ -100,6 +101,8 @@ class bugs : public unit_fixture
100101
void bug19938873_stmt();
101102

102103
void bug68523();
104+
105+
void bug66235();
103106
};
104107

105108
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)