Skip to content

Commit b7ee2f5

Browse files
committed
Bug #21053335 wasnull() method call fails with Valid input.
Initialize last_queried_column on navigation (next/last/...)
1 parent cf51692 commit b7ee2f5

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

driver/mysql_resultset.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ MySQL_ResultSet::checkScrollable() const
162162
if (resultset_type == sql::ResultSet::TYPE_FORWARD_ONLY) {
163163
throw sql::NonScrollableException("Nonscrollable result set");
164164
}
165+
// reset last_queried_column
166+
last_queried_column = -1;
165167
}
166168
/* }}} */
167169

@@ -351,12 +353,14 @@ MySQL_ResultSet::getDouble(const uint32_t columnIndex) const
351353
if (columnIndex == 0 || columnIndex > num_fields) {
352354
throw sql::InvalidArgumentException("MySQL_ResultSet::getDouble: invalid value of 'columnIndex'");
353355
}
356+
357+
last_queried_column = columnIndex;
358+
354359
if (row[columnIndex - 1] == NULL) {
355360
was_null = true;
356361
return 0.0;
357362
}
358363
was_null = false;
359-
last_queried_column = columnIndex;
360364
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT) {
361365
return static_cast<long double>(getInt64(columnIndex));
362366
}
@@ -497,9 +501,11 @@ MySQL_ResultSet::getInt64(const uint32_t columnIndex) const
497501
was_null = true;
498502
return 0;
499503
}
504+
505+
last_queried_column = columnIndex;
506+
500507
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
501508
was_null = false;
502-
last_queried_column = columnIndex;
503509
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
504510
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
505511
uint64_t uval = 0;
@@ -558,9 +564,11 @@ MySQL_ResultSet::getUInt64(const uint32_t columnIndex) const
558564
was_null = true;
559565
return 0;
560566
}
567+
568+
last_queried_column = columnIndex;
569+
561570
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
562571
was_null = false;
563-
last_queried_column = columnIndex;
564572
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
565573
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
566574
uint64_t uval = 0;
@@ -673,12 +681,13 @@ MySQL_ResultSet::getString(const uint32_t columnIndex) const
673681
throw sql::InvalidArgumentException("MySQL_ResultSet::getString: invalid value of 'columnIndex'");
674682
}
675683

684+
last_queried_column = columnIndex;
685+
676686
if (row == NULL || row[columnIndex - 1] == NULL) {
677687
was_null = true;
678688
return "";
679689
}
680690

681-
last_queried_column = columnIndex;
682691
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT) {
683692
char buf[30];
684693
snprintf(buf, sizeof(buf) - 1, "%llu", (unsigned long long) getUInt64(columnIndex));

test/unit/bugs/bugs.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,5 +733,62 @@ void bugs::bug66235()
733733
}
734734

735735

736+
void bugs::bug21053335()
737+
{
738+
logMsg("bugs::bug21053335");
739+
try
740+
{
741+
sql::ConnectOptionsMap connection_properties;
742+
743+
connection_properties["hostName"]=url;
744+
connection_properties["userName"]=user;
745+
connection_properties["password"]=passwd;
746+
747+
created_objects.clear();
748+
con.reset(driver->connect(connection_properties));
749+
con->setSchema(db);
750+
stmt.reset(con->createStatement());
751+
752+
stmt->execute("DROP TABLE IF EXISTS bug21053335");
753+
stmt->execute("CREATE TABLE bug21053335(c char(10))");
754+
stmt->execute("INSERT INTO bug21053335 values(NULL), (1)");
755+
res.reset(stmt->executeQuery("select c from bug21053335"));
756+
res->next();
757+
std::stringstream log;
758+
log << "Data :" <<res->getString(1);
759+
log<<"\nrs->wasNull(1) : "<<res->wasNull()<<std::endl;
760+
logMsg(log.str().c_str());
761+
762+
ASSERT(res->wasNull());
763+
764+
res->next();
765+
766+
try{
767+
ASSERT(res->wasNull());
768+
FAIL("Exception was not thrown by wasNull()");
769+
}
770+
catch (sql::SQLException & e)
771+
{
772+
// Everything is ok
773+
}
774+
775+
log.flush();
776+
log << "Data :" <<res->getString(1);
777+
log<<"\nrs->wasNull(1) : "<<res->wasNull()<<std::endl;
778+
logMsg(log.str().c_str());
779+
780+
ASSERT(!res->wasNull());
781+
782+
}
783+
catch (sql::SQLException & e)
784+
{
785+
FAIL("Exception thrown by wasNull()");
786+
throw;
787+
}
788+
789+
790+
}
791+
792+
736793
} /* namespace regression */
737794
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 4 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(bug21053335);
6465
}
6566

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

105106
void bug66235();
107+
108+
void bug21053335();
109+
106110
};
107111

108112
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)