Same problem. My solution, check if rows:
mysqlpp::StoreQueryResult res = query.store(); // fails
if(res.num_rows()){
...
}
문제
Buckle-up for this one.
It's weird I can't find anything online about an error like this but it's driving me nuts. Hopefully you guys can shed some light on the issue.
I'm using MySQL++ to get some basic data from a table. It connects to the database just fine and the query seems to work, but running mysql::Query::store() is causing a malloc error.
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;
}
A gdb backtrace gives me
(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 () is the function this is being run in.
IF I do the query twice (I did this out of curiosity),
mysqlpp::Query query = conn.query(sql);
query = conn.query(sql);
mysqlpp::StoreQueryResult res = query.store();
I get no malloc error, but I do get an SQL error:
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
My g++ version is
g++ (MacPorts gcc47 4.7.3_0) 4.7.3
Any ideas? I have used MySQL++ before and I never had any issues with this.
Also, this Load() sequence happens to be inside a dynamically linked library. (I have a load/unload system.) If I comment out the MySQL section, compile, and load the library, everything is fine. If I then uncomment the section, recompile, and reload the library (with the main program still running), the query runs successfully!!! wtf
Any help would be incredible. Thanks!!
올바른 솔루션이 없습니다
다른 팁
Same problem. My solution, check if rows:
mysqlpp::StoreQueryResult res = query.store(); // fails
if(res.num_rows()){
...
}