0

我有一个相当简单的调用,我正在尝试对数据库进行调用。我将所有内容都包含在 try/catch 和 if 语句中,但是……什么都没有。我知道我正在建立连接(每次尝试运行脚本时 MySQL 中的连接引用计数都会增加),但它似乎永远不会返回。代码是:

 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 运行调用,一切都按预期工作,所以这不会导致问题。

4

1 回答 1

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的例子

于 2011-09-12T10:19:45.960 回答