c++ - std::string 在迭代 mySQL 连接器查询结果时崩溃

标签 c++ mysql string crash std

我正在尝试使用 mysql 连接从我的数据库中获取一个 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++ 运行时库的某处有一些未初始化的内存... 它看起来像是在 std::string 析构函数中崩溃,这是有道理的,因为它在字符串范围完成时崩溃......

我最好的猜测是 libmysql 使用的是旧版本的 C++ 运行时(比如 msvcp90d.dll)并且它与新版本发生冲突...这有意义吗?

我在 windows 7 下,使用 mySQL Server 5.5,VS2010 Pro。全部为 32 位。谢谢!我很乐意发布任何需要的 mroe 信息。

编辑:在其他人阅读 DumbCoders 评论之前: MySQL Connector example 文档指定必须删除语句和结果集。

最佳答案

这个问题看起来和你的一样here .

关于c++ - std::string 在迭代 mySQL 连接器查询结果时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11055401/

相关文章:

javascript - 从 JSON 创建命名数组

mysql - 如果时间在当前范围内,如何自动设置 mySQL 中的单元格

javascript - 如何创建一个提取不同长度字符串的中间到末尾的函数?

c++ - 访问共享库中定义的单例

c++ - istreambuf_iterator<TCHAR> 的用法

mysql - 选择某个部门所有项目中的emp姓名

python - 在 Python 中使用 readline() 时,如何从列表中删除换行符或空字符串?

c - 反转字符串-运行时错误

c++ - 在单个语句中将临时字符串流转换为 c_str()

c++ - Qt - 如何在 30 天后删除日志文件且文件名不固定