【问题标题】:mysqlpp query not returning from executionmysqlpp查询未从执行返回
【发布时间】:2011-11-02 10:05:58
【问题描述】:

我正在尝试对数据库进行一个相当简单的调用。我将所有内容都包含在 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 运行调用,一切都会按预期运行,因此不会导致问题。

【问题讨论】:

    标签: mysql++


    【解决方案1】:

    你应该在 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的例子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-18
      • 2017-01-13
      • 1970-01-01
      相关资源
      最近更新 更多