Skip to content

Commit b81cfcf

Browse files
committed
Merge from trunk several corrections:
BUGS 21053335, 21066188, 21066301,21066575 and 21067193.
2 parents b7c06da + 69aa762 commit b81cfcf

File tree

6 files changed

+271
-10
lines changed

6 files changed

+271
-10
lines changed

driver/mysql_ps_resultset.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <string.h>
2929
#include <stdlib.h>
3030
#include <sstream>
31+
#include <limits>
3132
#include <boost/scoped_array.hpp>
3233

3334

@@ -134,7 +135,7 @@ MySQL_Prepared_ResultSet::absolute(const int new_pos)
134135
return true;
135136
}
136137
} else if (new_pos < 0) {
137-
if ((-new_pos) > (int) num_rows) {
138+
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
138139
row_position = 0; /* before first new_pos */
139140
} else {
140141
row_position = num_rows - (-new_pos) + 1;
@@ -980,9 +981,9 @@ MySQL_Prepared_ResultSet::getString(const uint32_t columnIndex) const
980981
char buf[18];
981982
MYSQL_TIME * t = static_cast<MYSQL_TIME *>(result_bind->rbind[columnIndex - 1].buffer);
982983
if (t->second_part) {
983-
snprintf(buf, sizeof(buf) - 1, "%s%02d:%02d:%02d.%06lu", t->neg? "-":"", t->hour, t->minute, t->second, t->second_part);
984+
snprintf(buf, sizeof(buf), "%s%02d:%02d:%02d.%06lu", t->neg? "-":"", t->hour, t->minute, t->second, t->second_part);
984985
} else {
985-
snprintf(buf, sizeof(buf) - 1, "%s%02d:%02d:%02d", t->neg? "-":"", t->hour, t->minute, t->second);
986+
snprintf(buf, sizeof(buf), "%s%02d:%02d:%02d", t->neg? "-":"", t->hour, t->minute, t->second);
986987
}
987988
CPP_INFO_FMT("It's a time %s", buf);
988989
return sql::SQLString(buf);

driver/mysql_resultset.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <stdlib.h>
2929
#include <stdio.h>
3030
#include <sstream>
31+
#include <limits>
3132
#include <boost/scoped_array.hpp>
3233

3334
#include <cppconn/exception.h>
@@ -100,7 +101,7 @@ MySQL_ResultSet::absolute(const int new_pos)
100101
return true;
101102
}
102103
} else if (new_pos < 0) {
103-
if ((-new_pos) > (int) num_rows) {
104+
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
104105
row_position = 0; /* before first new_pos */
105106
} else {
106107
row_position = num_rows - (-new_pos) + 1;
@@ -162,6 +163,8 @@ MySQL_ResultSet::checkScrollable() const
162163
if (resultset_type == sql::ResultSet::TYPE_FORWARD_ONLY) {
163164
throw sql::NonScrollableException("Nonscrollable result set");
164165
}
166+
// reset last_queried_column
167+
last_queried_column = -1;
165168
}
166169
/* }}} */
167170

@@ -351,12 +354,14 @@ MySQL_ResultSet::getDouble(const uint32_t columnIndex) const
351354
if (columnIndex == 0 || columnIndex > num_fields) {
352355
throw sql::InvalidArgumentException("MySQL_ResultSet::getDouble: invalid value of 'columnIndex'");
353356
}
357+
358+
last_queried_column = columnIndex;
359+
354360
if (row[columnIndex - 1] == NULL) {
355361
was_null = true;
356362
return 0.0;
357363
}
358364
was_null = false;
359-
last_queried_column = columnIndex;
360365
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT) {
361366
return static_cast<long double>(getInt64(columnIndex));
362367
}
@@ -493,13 +498,16 @@ MySQL_ResultSet::getInt64(const uint32_t columnIndex) const
493498
throw sql::InvalidArgumentException("MySQL_ResultSet::getInt64: invalid value of 'columnIndex'");
494499
}
495500

501+
last_queried_column = columnIndex;
502+
496503
if (row[columnIndex - 1] == NULL) {
497504
was_null = true;
498505
return 0;
499506
}
507+
508+
500509
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
501510
was_null = false;
502-
last_queried_column = columnIndex;
503511
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
504512
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
505513
uint64_t uval = 0;
@@ -554,13 +562,16 @@ MySQL_ResultSet::getUInt64(const uint32_t columnIndex) const
554562
throw sql::InvalidArgumentException("MySQL_ResultSet::getUInt64: invalid value of 'columnIndex'");
555563
}
556564

565+
last_queried_column = columnIndex;
566+
557567
if (row[columnIndex - 1] == NULL) {
558568
was_null = true;
559569
return 0;
560570
}
571+
572+
561573
CPP_INFO_FMT("%ssigned", (getFieldMeta(columnIndex)->flags & UNSIGNED_FLAG)? "un":"");
562574
was_null = false;
563-
last_queried_column = columnIndex;
564575
if (getFieldMeta(columnIndex)->type == MYSQL_TYPE_BIT &&
565576
getFieldMeta(columnIndex)->flags != (BINARY_FLAG|UNSIGNED_FLAG)) {
566577
uint64_t uval = 0;
@@ -673,12 +684,13 @@ MySQL_ResultSet::getString(const uint32_t columnIndex) const
673684
throw sql::InvalidArgumentException("MySQL_ResultSet::getString: invalid value of 'columnIndex'");
674685
}
675686

687+
last_queried_column = columnIndex;
688+
676689
if (row == NULL || row[columnIndex - 1] == NULL) {
677690
was_null = true;
678691
return "";
679692
}
680693

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

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;

driver/nativeapi/mysql_native_statement_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ MySQL_NativeStatementWrapper::MySQL_NativeStatementWrapper(::st_mysql_stmt * _st
5656
/* {{{ MySQL_NativeStatementWrapper::~MySQL_NativeStatementWrapper() */
5757
MySQL_NativeStatementWrapper::~MySQL_NativeStatementWrapper()
5858
{
59+
stmt_free_result();
5960
api->stmt_close(stmt);
6061
}
6162
/* }}} */

0 commit comments

Comments
 (0)