为这个系好安全带。
奇怪的是,我在网上找不到关于这样一个错误的任何东西,但这让我发疯了。希望你们能对这件事有所了解。
我使用MySQL++从表中获取一些基本数据。它与数据库连接得很好,而且查询看起来很好,但是运行mysql:: query ::store()会导致malloc错误。
mysqlpp::Connection conn(false);
if(conn.connect("demo", "127.0.0.1", "root", "")) // works
{
std::string sql = "SELECT * FROM `items`";
mysqlpp::Query query = conn.query(sql); // works
mysqlpp::StoreQueryResult res = query.store(); // fails
if(res)
{
mysqlpp::StoreQueryResult::const_iterator it;
for(it = res.begin(); it != res.end(); ++it)
{
mysqlpp::Row row = *it;
// Do some things
}
}
else
{
std::cerr<<"Failed to get item list: "<<query.error()<<std::endl;
return false;
}
}
else
{
std::cerr<<"DB connection failed: "<<conn.error()<<std::endl;
return false;
}gdb回溯给我
(gdb) backtrace
#0 0x00007fff841ed499 in malloc_error_break ()
#1 0x00007fff84117183 in free ()
#2 0x000000010029d66c in mysqlpp::Field::~Field ()
#3 0x0000000100493e4d in mysqlpp::ResultBase::ResultBase (this=0x1004805c8, res=0x100480660, dbd=0x100480660, te=122) at result.cpp:40
#4 0x0000000100494690 in mysqlpp::StoreQueryResult::StoreQueryResult (this=0x100480730, res=0x100303e30, dbd=0x100802600) at result.cpp:103
#5 0x0000000100491242 in mysqlpp::Query::store (this=0x3, str=0x100303da0 "SELECT * FROM `items`", len=4298128944) at query.cpp:534
#6 0x00000001004916dc in mysqlpp::Query::store (this=0x3, s=@0x100480848) at query.cpp:508
#7 0x00000001004917c3 in mysqlpp::Query::store (this=0x3) at query.cpp:483
#8 0x0000000100297464 in Load ()
....Load ()是正在运行的函数。
如果我做了两次查询(出于好奇我这样做了),
mysqlpp::Query query = conn.query(sql);
query = conn.query(sql);
mysqlpp::StoreQueryResult res = query.store();我没有收到malloc错误,但我确实得到了一个SQL错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM `items`' at line 1我的g++版本是
g++ (MacPorts gcc47 4.7.3_0) 4.7.3有什么想法吗?我以前使用过MySQL++,对此我从来没有任何问题。
同时,这个Load()序列恰好在一个动态链接库中。(我有一个加载/卸载系统)。如果我注释掉了MySQL部分,编译并加载了库,那么一切都很好。如果取消注释,重新编译并重新加载库(主程序仍在运行),查询将成功运行!!wtf!
任何帮助都是不可思议的。谢谢!!
发布于 2015-09-08 23:53:46
同样的问题。我的解决方案,检查行:
mysqlpp::StoreQueryResult res = query.store(); // fails
if(res.num_rows()){
...
}https://stackoverflow.com/questions/16431260
复制相似问题