gpt4 book ai didi

c++ - mysqlpp::Query::store() 上的 MySQL++ malloc_error_break

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:58 24 4
gpt4 key购买 nike

为这个系上安全带。

很奇怪,我在网上找不到任何关于此类错误的信息,但这让我抓狂。希望你们能对这个问题有所了解。

我正在使用 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 () 是正在运行的函数。

IF 我做了两次查询(我这样做是出于好奇),

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

任何帮助都是不可思议的。谢谢!!

最佳答案

同样的问题。我的解决方案,检查行是否:

mysqlpp::StoreQueryResult res = query.store(); // fails
if(res.num_rows()){
...
}

关于c++ - mysqlpp::Query::store() 上的 MySQL++ malloc_error_break,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16431260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com