2011-08-24 72 views
0

我有一个相当简单的调用,我正在试图做一个数据库。我已经把所有东西都包围在try/catch中,如果有陈述,但是......什么都没有。我知道我正在建立连接(每次我尝试运行脚本时,都会以MySQL为增量进行连接重新计数),但它似乎永远不会返回。代码是:mysqlpp查询没有从执行返回

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*/ } 

,我也得到:

About to call query 

我的唯一输出。 我有更多的调试在那里(查询正在放在一起,连接是正确的,等)。 任何人都知道可能发生了什么,或者我应该接下来检查什么?

谢谢!

- 编辑:如果我直接从MySQL运行调用,一切都按预期工作,所以这不会导致问题。

回答

0

你应该在conn.query()中调用查询;像

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; 
    } 
} 

可以参考http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html的例子