I have a fairly simple call I'm trying to make to a database. I have everything surrounded in try/catch and if statements, but... nothing. I know I'm making the connection (the connection refcount in MySQL increments each time I try running the script), but it never seems to return. Code is:
if (!conn.connect(db, server, username, pass))
{ /* Log error to a file */}
try
{
mysqlpp::Query query = conn.query();
query << "CALL db.test('1', '2')";
std::cout << "About to call query" << std::endl;
if (mysqlpp::StoreQueryResult res = query.store())
{
std::string toReturn = "";
res[0][0].to_string(toReturn);
std::cout << "Query called. Result: " << toReturn << std::endl;
}
}
catch(Exception e)
{ /*Output caught exception*/ }
and I get:
About to call query
as my sole output. I have more debugging in there (query is being put together correctly, connection is correct, etc). Anyone have any idea what might be happening, or what I should check next?
Thanks!
-- Edit: If I run the call straight from MySQL, everything works as expected, so that's not causing the problem.
You should call the query inside conn.query(); Like
std::cout << "About to call query" << std::endl;
mysqlpp::Query query = conn.query("CALL db.test('1', '2')");
if (mysqlpp::StoreQueryResult res = query.store())
{
std::string toReturn = ""; //this is not necessary
res[0][0].to_string(toReturn); //this is not necessary
for (size_t i = 0; i < res.num_rows(); ++i)
{
std::cout << "Query called. Result: " << res[i][0] << std::endl;
}
}
you can refer http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html for examples