MySQL Forums
Forum List  »  Connector/C++

Re: Microsoft C++ Exception std::out_of_range mysql-connector-c++-8.0.18-winx64
Posted by: Rand Olmsted
Date: November 25, 2019 10:00AM

I buillt 8.0.18 from source with openssl (also build from source) statically linked. I had to use Visual Studio 2017 for the build. Visual Studio 2019 gave an error that mysqlx_row_struct could not be found. I build with this cmake invocation, followed by using the Visual Studio solution > project ALL_BUILD.

cmake -Wno-dev -B .\. -S .\.. -G "Visual Studio 15 2017 Win64" -DBUILD_STATIC=ON -DWITH_DOC=ON -DCMAKE_INSTALL_PREFIX=..\..\mysql-connector-cpp-8.0.18\lib -DWITH_SSL=..\..\..\openssl-1.1.1d\lib --loglevel=STATUS --check-system-vars

I am now able to step through all of the connector code.

When attempting to read the database the standard library <map> throws std::out_of_range from "_NODISCARD mapped_type& at(const key_type& _Keyval)". _Keyval is 0.
The calling location is in reslut.h function "Value& get(col_count_t pos)". pos is 0. Line of code that throws: "return m_vals.at(pos);"
The exception is not fatal and the returned result (a pair of strings, one of which is a path to a file) works to open the file without error.

code to reproduce the error (I tried to mirror what I have in the real app as much as possible):

#include <mysqlx/xdevapi.h>
#include <string>
using namespace ::mysqlx;
#define DATABASE_URL L"mysqlx://test_operator:2694@localhost:33060"
#define DATABASE_SCHEMA_CONFIGURATION L"test_stand_configuration"
int main( int argc, char** argv )
{
Session session( DATABASE_URL );
RowResult result;
Row row;
Value value;
size_t row_count = 0;
std::vector<std::wstring> paths;
std::wstring path_id;
std::wstring path;
try
{
result = session.getSchema( DATABASE_SCHEMA_CONFIGURATION )
.getTable( L"image_resource_list" )
.select( L"resource_id", "name" )
.execute();
row_count = result.count();
if( row_count > 0 )
{
row = result.fetchOne();
while( !row.isNull() )
{
value = row[0]; // throws nonfatal std::out_of_range
path_id = static_cast<std::wstring>( value );
value = row[1]; // throws nonfatal std::out_of_range
path = static_cast<std::wstring>( value );
std::wcout << L"Path ID: " << path_id << L" Path: " << path << std::endl;
row = result.fetchOne();
}
}
}
catch( std::exception& e )
{
cout << "Exception Message: " << e.what() << endl;
}
catch( ... )
{
cout << "UNKNOWN exception caught" << endl;
}
}

Table being read:

CREATE TABLE `image_resource_list` (
`resource_id` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
`name` varchar(260) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
PRIMARY KEY (`resource_id`),
UNIQUE KEY `resource_id_UNIQUE` (`resource_id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='List of application image resources keyed to a resource id';

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.