问题描述
已经2天了,我试图了解为什么会发生这种情况,但是我没有足够的调试技巧来了解为什么会发生这种情况.
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.
我需要使用 sql :: ConnectOptionsMap ,这样我才能传递所需的连接选项,例如字符集等.
I need to use the sql::ConnectOptionsMap so I can pass my desired connection options such as charset, etc.
一个简单的例子:
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));
在调试下与VS 2017一起编译:
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...
请告知.
推荐答案
我终于找到了这个问题的答案,这个问题在任何地方都没有记录.您可以使用"sql :: ConnectOptionsMap connection_properties;" 仅当您静态链接时. (mysqlcppconn-static.lib)
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)
我是怎么发现的?遵循以下令人惊奇的信息: http://www.voidcn.com/article/p-yltwwlte-pd.html
How I found this out ? Following this amazing information from: http://www.voidcn.com/article/p-yltwwlte-pd.html
报价:
但是我确实测试了本文中的代码并将其添加到mysql_connection.cpp中,该错误消失了,但仍然无法正常工作.
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.
我的警告:
我正在构建自己的mysql-connector-cpp-master的调试"版本,由于某种原因,编译未达到预期的效果".例如,在我的编译中,"mysqlcppconn-static.lib"不能编译为Debug,只能编译为"RelWithDebInfo",只有10 MB,而正式"编译为64 MB.
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.
结论:
您必须从MySQL网站静态链接发布版本(mysqlcppconn-static.lib),才能使用"sql :: ConnectOptionsMap".我真的希望他们能醒来,并为人们和文档制作适当的库.
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.
如果我能找到在Debug模式下构建它的方法,我将发布更新.
If I can find a way to build this in Debug mode, I shall post an update.
这篇关于旧版MySQL Connector C ++使用sql :: ConnectOptionsMap异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!