Skip to content

Commit

Permalink
Fixed bug 93895
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Degtyariov committed Feb 21, 2019
1 parent ecee076 commit 414aa55
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Connector/ODBC ${CONNECTOR_BASE_VERSION},
SET(CPACK_PACKAGE_NAME "mysql-connector-odbc${EXTRA_NAME_SUFFIX}")

SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.txt")
if(EXISTS "${CMAKE_SOURCE_DIR}/README.txt")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.txt")
else()
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
endif()

SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}-src")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}")
Expand Down Expand Up @@ -511,7 +515,13 @@ cmake/sql.*\\\\.c$
INCLUDE(cmake/info_bin.cmake)

INSTALL(FILES LICENSE.txt DESTINATION .)
INSTALL(FILES README.txt DESTINATION .)

if(EXISTS "${CMAKE_SOURCE_DIR}/README.txt")
INSTALL(FILES README.txt DESTINATION .)
else()
INSTALL(FILES README.md DESTINATION .)
INSTALL(FILES CONTRIBUTING.md DESTINATION .)
endif()

IF(WIN32)

Expand Down
66 changes: 22 additions & 44 deletions driver/my_prepared_stmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ SQLRETURN ssps_fetch_chunk(STMT *stmt, char *dest, unsigned long dest_bytes, uns
}


bool is_varlen_type(enum enum_field_types type)
{
return (type == MYSQL_TYPE_BLOB ||
type == MYSQL_TYPE_TINY_BLOB ||
type == MYSQL_TYPE_MEDIUM_BLOB ||
type == MYSQL_TYPE_LONG_BLOB);
}

/* The structure and following allocation function are borrowed from c/c++ and adopted */
typedef struct tagBST
{
Expand All @@ -376,18 +384,9 @@ typedef struct tagBST
otherwise libmysqlclient throws the assertion.
This will be reallocated later.
*/
bool is_fake_blob_alloc()
{
return (type == MYSQL_TYPE_BLOB ||
type == MYSQL_TYPE_TINY_BLOB ||
type == MYSQL_TYPE_MEDIUM_BLOB ||
type == MYSQL_TYPE_LONG_BLOB) &&
size == 1;
}

bool is_null_alloc()
bool is_varlen_alloc()
{
return (type != MYSQL_TYPE_NULL && buffer == NULL);
return is_varlen_type(type);
}
} st_buffer_size_type;

Expand Down Expand Up @@ -511,24 +510,6 @@ static MYSQL_ROW fetch_varlength_columns(STMT *stmt, MYSQL_ROW columns)

for (i= 0; i < num_fields; ++i)
{
// The allocated buffer for these types was set to 1 byte
// to keep mysqlclient asserts happy
//if (stmt->result_bind[i].buffer_length == 1 &&
// stmt->result_bind[i].buffer &&
// (
// stmt->result_bind[i].buffer_type == MYSQL_TYPE_MEDIUM_BLOB ||
// stmt->result_bind[i].buffer_type == MYSQL_TYPE_LONG_BLOB ||
// stmt->result_bind[i].buffer_type == MYSQL_TYPE_BLOB ||
// stmt->result_bind[i].buffer_type == MYSQL_TYPE_STRING ||
// stmt->result_bind[i].buffer_type == MYSQL_TYPE_VAR_STRING
// )
// )
//{
// x_free(stmt->result_bind[i].buffer);
// stmt->result_bind[i].buffer = NULL;
// stmt->array[i] = NULL;
// stmt->result_bind[i].buffer_length = 0;
//}

if (i == stream_column)
{
Expand All @@ -537,21 +518,19 @@ static MYSQL_ROW fetch_varlength_columns(STMT *stmt, MYSQL_ROW columns)
}
else
{
if (stmt->result_bind[i].buffer == NULL)
if (is_varlen_type(stmt->result_bind[i].buffer_type) &&
stmt->result_bind[i].buffer_length < *stmt->result_bind[i].length)
{
if (stmt->lengths[i] < *stmt->result_bind[i].length)
{
/* TODO Realloc error proc */
stmt->array[i]= (char*)myodbc_realloc(stmt->array[i], *stmt->result_bind[i].length,
MYF(MY_ALLOW_ZERO_PTR));
stmt->lengths[i]= *stmt->result_bind[i].length;
}
/* TODO Realloc error proc */
stmt->array[i]= (char*)myodbc_realloc(stmt->array[i], *stmt->result_bind[i].length,
MYF(MY_ALLOW_ZERO_PTR));
stmt->lengths[i]= *stmt->result_bind[i].length;
}

stmt->result_bind[i].buffer= stmt->array[i];
stmt->result_bind[i].buffer_length= stmt->lengths[i];
stmt->result_bind[i].buffer= stmt->array[i];
stmt->result_bind[i].buffer_length= stmt->lengths[i];

mysql_stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0);
}
mysql_stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0);
}
}

Expand Down Expand Up @@ -630,7 +609,7 @@ int STMT::ssps_bind_result()
/*
Marking that there are columns that will require buffer (re) allocating
*/
if ( p.is_null_alloc() || p.is_fake_blob_alloc())
if ( p.is_varlen_alloc())
{
fix_fields= fetch_varlength_columns;

Expand Down Expand Up @@ -665,8 +644,7 @@ BOOL ssps_0buffers_truncated_only(STMT *stmt)
for (i= 0; i < num_fields; ++i)
{
if (*stmt->result_bind[i].error != 0
&& stmt->result_bind[i].buffer_length > 0
&& stmt->result_bind[i].buffer != NULL)
&& stmt->result_bind[i].buffer_length >= (*stmt->result_bind[i].length))
{
return FALSE;
}
Expand Down

0 comments on commit 414aa55

Please sign in to comment.