It's been 2 days already that I am trying to understand why is this happening, however I do not have enough debugging skills to understand why is this occurring.
I need to use the sql::ConnectOptionsMap so I can pass my desired connection options such as charset, etc.
A simple example taken:
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"] = sql::SQLString("localhost");
connection_properties["userName"] = sql::SQLString("username");
connection_properties["password"] = sql::SQLString("password");
connection_properties["CLIENT_MULTI_STATEMENTS"] = (true);
sql::Driver * driver = get_driver_instance();
std::unique_ptr<sql::Connection> con(driver->connect(connection_properties));
Compiled with VS 2017, under debug:
Exception thrown at 0x00007FFFECC811D0 (vcruntime140d.dll) in Demo.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
After creating some "mini dumps", I can see the code is crashing here:
_NODISCARD static _CONSTEXPR17 int compare(_In_reads_(_Count) const char * const _First1,
_In_reads_(_Count) const char * const _First2, const size_t _Count) noexcept // strengthened
{ // compare [_First1, _First1 + _Count) with [_First2, ...)
#if _HAS_CXX17
return (__builtin_memcmp(_First1, _First2, _Count));
#else /* _HAS_CXX17 */
return (_CSTD memcmp(_First1, _First2, _Count)); <-- HERE
#endif /* _HAS_CXX17 */
}
Has anyone encountered this before ? I have searched a lot, and could not find anyone having this issue until now.
I really cannot understand why this is happening, since there is nothing custom, just an example from the docs...
Please advise.
I found finally the answer to this problem, which is not documented anywhere. You can use "sql::ConnectOptionsMap connection_properties;" ONLY if you are statically linking the library. (mysqlcppconn-static.lib)
How I found this out ? Following this amazing information from: http://www.voidcn.com/article/p-yltwwlte-pd.html
Quote:
The strings used in the interface are all SQLString. Although it is a further wrapper of std::string, it is impossible to pass a std::string object as a parameter. Because it is a way of dynamic linking, the memory management in the DLL has no connection with the EXE. Passing the object in the past will cause an exception: bad_alloc
I did however test the code from the article and added into the mysql_connection.cpp, and the error is gone but it will still not work.
My caveat:
I was building my own "Debug" version of the mysql-connector-cpp-master, and for some reason the compilation is not "as expected". For example in my compilation the "mysqlcppconn-static.lib" cannot be compiled as Debug, only "RelWithDebInfo" and is only 10 MB, whilst the "official" one is 64 MB.
Conclusion:
You must statically link the Release version (mysqlcppconn-static.lib) from the MySQL website in order to use "sql::ConnectOptionsMap". I really hope they will wake up and make a proper lib for people and documentation as well.
If I can find a way to build this in Debug mode, I shall post an update.
User contributions licensed under CC BY-SA 3.0