我正在尝试使用mysql connexion
从我的数据库中获取std :: string以下是简单的代码:
sql::Statement *stmt = con->createStatement();
sql::ResultSet *res = stmt->executeQuery("SELECT * FROM test.new_table");
while (res->next()) {
std::string somestring = res->getString("idnew_table");
} //crashes here
delete res;
delete stmt;
所以,executeQuery很好,我进入循环,如果我中断,预期的结果是在某些字符串中。在somestring声明之后,我逐步向循环结束,并在下一次迭代之前崩溃!
这是调用堆栈:
> msvcp100d.dll!std::_Lockit::_Lockit(int kind) Line 64 + 0x14 bytes C++
msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 200 C++
CM.dll!std::_String_val<char,std::allocator<char> >::~_String_val<char,std::allocator<char> >() Line 478 + 0xb bytes C++
CM.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 755 + 0xf bytes C++
CM.dll!DAL::GetInfo() Line 45 + 0xc bytes C++
输出:
First-chance exception at 0x1038ad4a (msvcp100d.dll) in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
First-chance exception at 0x76f5016e in CMLauncher.exe: 0x00000000: The operation completed successfully.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0x00000000: The operation completed successfully.
所以看起来我在C ++运行库lib中的某个地方有一些未初始化的内存... 它看起来像是在std :: string析构函数中崩溃了,哪种有意义,因为它在字符串的范围完成时崩溃...
我最好的猜测是libmysql正在使用较旧版本的C ++运行时(比如msvcp90d.dll)并且它与新版本发生冲突......这是否有意义?
我在Windows 7下,使用mySQL Server 5.5,VS2010 Pro。全部在32位。谢谢!我很乐意发布所需的任何信息。
编辑:在其他人阅读DumbCoders评论之前: MySQL Connector example 该文档指定必须删除语句和resultSet。