Skip to content

Commit 507c29a

Browse files
committed
Bug #14520822 (on prepared statments) - getString on BIT fields with wrong output.
Modify previous unit test. Add new unit test with prepared statments.
1 parent cf51692 commit 507c29a

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

driver/mysql_util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ mysql_type_to_datatype(const MYSQL_FIELD * const field)
340340
{
341341
switch (field->type) {
342342
case MYSQL_TYPE_BIT:
343-
return sql::DataType::BIT;
343+
if (field->flags !=(BINARY_FLAG|UNSIGNED_FLAG))
344+
return sql::DataType::BIT;
345+
return sql::DataType::BINARY;
344346
case MYSQL_TYPE_DECIMAL:
345347
case MYSQL_TYPE_NEWDECIMAL:
346348
return sql::DataType::DECIMAL;

test/unit/bugs/bugs.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ void bugs::bug66235()
703703
stmt.reset(con->createStatement());
704704
stmt->execute("DROP TABLE IF EXISTS test");
705705
stmt->execute("CREATE TABLE test(id BIT(3))");
706-
stmt->execute("INSERT INTO test(id) VALUES(1), (10), (1), (1), (10), (111);");
706+
stmt->execute("INSERT INTO test(id) VALUES(0b1), (0b10), (0b1), (0b1), (0b10), (0b111);");
707707

708708
res.reset(stmt->executeQuery("SELECT MAX(id), MIN(id) FROM test"));
709709
while (res->next())
@@ -733,5 +733,47 @@ void bugs::bug66235()
733733
}
734734

735735

736+
void bugs::bug14520822()
737+
{
738+
logMsg("bug::bug14520822");
739+
try
740+
{
741+
stmt.reset(con->createStatement());
742+
stmt->execute("DROP TABLE IF EXISTS bug14520822");
743+
stmt->execute("CREATE TABLE bug14520822(b BIT NOT NULL DEFAULT 0)");
744+
stmt->execute("INSERT INTO bug14520822(b) VALUES(0b0), (0b1)");
745+
746+
res.reset(stmt->executeQuery("select min(b) ,max(b) from bug14520822"));
747+
res->next();
748+
ASSERT_EQUALS("0", res->getString(1));
749+
ASSERT_EQUALS("1", res->getString(2));
750+
ASSERT_EQUALS(false, res->getBoolean(1));
751+
ASSERT_EQUALS(true, res->getBoolean(2));
752+
ASSERT_EQUALS(0L, res->getInt64(1));
753+
ASSERT_EQUALS(1L, res->getInt64(2));
754+
755+
pstmt.reset(con->prepareStatement("select min(b) ,max(b) from bug14520822"));
756+
res.reset(pstmt->executeQuery());
757+
res->next();
758+
ASSERT_EQUALS("0", res->getString(1));
759+
ASSERT_EQUALS("1", res->getString(2));
760+
ASSERT_EQUALS(false, res->getBoolean(1));
761+
ASSERT_EQUALS(true, res->getBoolean(2));
762+
ASSERT_EQUALS(0L, res->getInt64(1));
763+
ASSERT_EQUALS(1L, res->getInt64(2));
764+
765+
766+
}
767+
catch (sql::SQLException &e)
768+
{
769+
logErr(e.what());
770+
logErr("SQLState: " + std::string(e.getSQLState()));
771+
fail(e.what(), __FILE__, __LINE__);
772+
}
773+
774+
775+
}
776+
777+
736778
} /* namespace regression */
737779
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class bugs : public unit_fixture
6161
TEST_CASE(bug19938873_stmt);
6262
TEST_CASE(bug68523);
6363
TEST_CASE(bug66235);
64+
TEST_CASE(bug14520822);
6465
}
6566

6667
/**
@@ -103,6 +104,8 @@ class bugs : public unit_fixture
103104
void bug68523();
104105

105106
void bug66235();
107+
108+
void bug14520822();
106109
};
107110

108111
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)