Skip to content

Commit bb1439a

Browse files
committed
Fix bug#22292073 when getting INT from JSON_EXTRACT.
1 parent c7a1412 commit bb1439a

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

driver/mysql_ps_resultset.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ MySQL_Prepared_ResultSet::getDouble(const uint32_t columnIndex) const
446446
case sql::DataType::LONGVARBINARY:
447447
case sql::DataType::SET:
448448
case sql::DataType::ENUM:
449+
case sql::DataType::JSON:
449450
{
450451
CPP_INFO("It's a string");
451452
long double ret = sql::mysql::util::strtold(getString(columnIndex).c_str(), NULL);
@@ -614,6 +615,7 @@ MySQL_Prepared_ResultSet::getInt64_intern(const uint32_t columnIndex, bool /* cu
614615
case sql::DataType::LONGVARBINARY:
615616
case sql::DataType::SET:
616617
case sql::DataType::ENUM:
618+
case sql::DataType::JSON:
617619
CPP_INFO("It's a string");
618620
return strtoll(getString(columnIndex).c_str(), NULL, 10);
619621
case sql::DataType::BIT:
@@ -761,6 +763,7 @@ MySQL_Prepared_ResultSet::getUInt64_intern(const uint32_t columnIndex, bool /* c
761763
case sql::DataType::LONGVARBINARY:
762764
case sql::DataType::SET:
763765
case sql::DataType::ENUM:
766+
case sql::DataType::JSON:
764767
CPP_INFO("It's a string");
765768
return strtoull(getString(columnIndex).c_str(), NULL, 10);
766769
case sql::DataType::BIT:

test/unit/bugs/bugs.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,5 +982,55 @@ void bugs::bug21152054()
982982

983983
}
984984

985+
void bugs::bug22292073()
986+
{
987+
988+
stmt->execute("DROP TABLE IF EXISTS bug22292073");
989+
stmt->execute("create table bug22292073 (jdoc JSON);" );
990+
stmt->execute("insert into bug22292073 values('{ \"name\": \"abc\", \"age\": 1 , \"misc\":\
991+
1.2}'), ('{ \"name\": \"abcdef\", \"age\": 31 , \"misc\": 1.237843}');" );
992+
pstmt.reset( con->prepareStatement("select JSON_EXTRACT(jdoc, '$.age') from bug22292073;") );
993+
res.reset( pstmt->executeQuery() );
994+
995+
res->next();
996+
997+
ASSERT_EQUALS(true, res->getBoolean(1));
998+
ASSERT_EQUALS(1, res->getInt(1));
999+
ASSERT_EQUALS(1L, res->getInt64(1));
1000+
ASSERT_EQUALS(1, res->getUInt(1));
1001+
ASSERT_EQUALS(1UL, res->getUInt64(1));
1002+
ASSERT_EQUALS(1.0, res->getDouble(1));
1003+
1004+
res->next();
1005+
1006+
ASSERT_EQUALS(true, res->getBoolean(1));
1007+
ASSERT_EQUALS(31, res->getInt(1));
1008+
ASSERT_EQUALS(31L, res->getInt64(1));
1009+
ASSERT_EQUALS(31, res->getUInt(1));
1010+
ASSERT_EQUALS(31UL, res->getUInt64(1));
1011+
ASSERT_EQUALS(31.0, res->getDouble(1));
1012+
1013+
stmt.reset(con->createStatement());
1014+
res.reset(stmt->executeQuery("select JSON_EXTRACT(jdoc, '$.age') from bug22292073;"));
1015+
1016+
res->next();
1017+
1018+
ASSERT_EQUALS(true, res->getBoolean(1));
1019+
ASSERT_EQUALS(1, res->getInt(1));
1020+
ASSERT_EQUALS(1L, res->getInt64(1));
1021+
ASSERT_EQUALS(1, res->getUInt(1));
1022+
ASSERT_EQUALS(1UL, res->getUInt64(1));
1023+
ASSERT_EQUALS(1.0, res->getDouble(1));
1024+
1025+
res->next();
1026+
1027+
ASSERT_EQUALS(true, res->getBoolean(1));
1028+
ASSERT_EQUALS(31, res->getInt(1));
1029+
ASSERT_EQUALS(31L, res->getInt64(1));
1030+
ASSERT_EQUALS(31, res->getUInt(1));
1031+
ASSERT_EQUALS(31UL, res->getUInt64(1));
1032+
ASSERT_EQUALS(31.0, res->getDouble(1));
1033+
}
1034+
9851035
} /* namespace regression */
9861036
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class bugs : public unit_fixture
6767
TEST_CASE(bug21067193);
6868
TEST_CASE(bug21066575);
6969
TEST_CASE(bug21152054);
70+
TEST_CASE(bug22292073);
7071
}
7172

7273
/**
@@ -122,6 +123,8 @@ class bugs : public unit_fixture
122123

123124
void bug21152054();
124125

126+
void bug22292073();
127+
125128
};
126129

127130
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)