Skip to content

Commit 0779423

Browse files
committed
Merge with trunk
2 parents 507c29a + 72142ee commit 0779423

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

driver/mysql_resultset.cpp

Lines changed: 15 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
}
@@ -493,13 +497,16 @@ MySQL_ResultSet::getInt64(const uint32_t columnIndex) const
493497
throw sql::InvalidArgumentException("MySQL_ResultSet::getInt64: invalid value of 'columnIndex'");
494498
}
495499

500+
last_queried_column = columnIndex;
501+
496502
if (row[columnIndex - 1] == NULL) {
497503
was_null = true;
498504
return 0;
499505
}
506+
507+
500508
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
501509
was_null = false;
502-
last_queried_column = columnIndex;
503510
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
504511
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
505512
uint64_t uval = 0;
@@ -554,13 +561,16 @@ MySQL_ResultSet::getUInt64(const uint32_t columnIndex) const
554561
throw sql::InvalidArgumentException("MySQL_ResultSet::getUInt64: invalid value of 'columnIndex'");
555562
}
556563

564+
last_queried_column = columnIndex;
565+
557566
if (row[columnIndex - 1] == NULL) {
558567
was_null = true;
559568
return 0;
560569
}
570+
571+
561572
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
562573
was_null = false;
563-
last_queried_column = columnIndex;
564574
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
565575
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
566576
uint64_t uval = 0;
@@ -673,12 +683,13 @@ MySQL_ResultSet::getString(const uint32_t columnIndex) const
673683
throw sql::InvalidArgumentException("MySQL_ResultSet::getString: invalid value of 'columnIndex'");
674684
}
675685

686+
last_queried_column = columnIndex;
687+
676688
if (row == NULL || row[columnIndex - 1] == NULL) {
677689
was_null = true;
678690
return "";
679691
}
680692

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

test/unit/bugs/bugs.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,11 @@ void bugs::bug66235()
735735

736736
void bugs::bug14520822()
737737
{
738+
738739
logMsg("bug::bug14520822");
739740
try
740741
{
742+
741743
stmt.reset(con->createStatement());
742744
stmt->execute("DROP TABLE IF EXISTS bug14520822");
743745
stmt->execute("CREATE TABLE bug14520822(b BIT NOT NULL DEFAULT 0)");
@@ -762,15 +764,60 @@ void bugs::bug14520822()
762764
ASSERT_EQUALS(0L, res->getInt64(1));
763765
ASSERT_EQUALS(1L, res->getInt64(2));
764766

765-
766767
}
767768
catch (sql::SQLException &e)
768769
{
769770
logErr(e.what());
770771
logErr("SQLState: " + std::string(e.getSQLState()));
771772
fail(e.what(), __FILE__, __LINE__);
772773
}
774+
}
775+
776+
void bugs::bug21053335()
777+
{
778+
779+
logMsg("bugs::bug21053335");
780+
try
781+
{
782+
783+
stmt->execute("DROP TABLE IF EXISTS bug21053335");
784+
stmt->execute("CREATE TABLE bug21053335(c char(10))");
785+
stmt->execute("INSERT INTO bug21053335 values(NULL), (1)");
786+
res.reset(stmt->executeQuery("select c from bug21053335"));
787+
res->next();
788+
std::stringstream log;
789+
log << "Data :" <<res->getString(1);
790+
log<<"\nrs->wasNull(1) : "<<res->wasNull()<<std::endl;
791+
logMsg(log.str().c_str());
792+
793+
ASSERT(res->wasNull());
794+
795+
res->next();
796+
797+
try{
798+
ASSERT(res->wasNull());
799+
FAIL("Exception was not thrown by wasNull()");
800+
}
801+
catch (sql::SQLException & e)
802+
{
803+
// Everything is ok
804+
}
805+
806+
log.flush();
807+
log << "Data :" <<res->getString(1);
808+
log<<"\nrs->wasNull(1) : "<<res->wasNull()<<std::endl;
809+
logMsg(log.str().c_str());
810+
811+
ASSERT(!res->wasNull());
812+
813+
814+
}
773815

816+
catch (sql::SQLException &e)
817+
{
818+
FAIL("Exception thrown by wasNull()");
819+
throw;
820+
}
774821

775822
}
776823

test/unit/bugs/bugs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class bugs : public unit_fixture
6262
TEST_CASE(bug68523);
6363
TEST_CASE(bug66235);
6464
TEST_CASE(bug14520822);
65+
TEST_CASE(bug21053335);
6566
}
6667

6768
/**
@@ -106,6 +107,9 @@ class bugs : public unit_fixture
106107
void bug66235();
107108

108109
void bug14520822();
110+
111+
void bug21053335();
112+
109113
};
110114

111115
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)