我已经阅读了教程,我通常了解它是如何工作的:http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#simple
我正在尝试构建这个mysql++代码,并且我得到了一个错误:
std::ostringstream query3;
query3<<"select pipe_id from pipe where version_id='"<<id<<"'";
std::storeQueryResult ares=query3.store();
for(size_t i=0;i<ares.num_rows();i++)
cout<<ares[i]["version_id"]<<ares[i]["pipe_id"]<<std::endl;
mysql_query(&mysql,query3.str().c_str());错误是store不是ostringstream的成员。我不知道如何纠正这个问题。
嗨梅林
谢谢你的代码,看看我的问题。
我尝试了上面的代码,但是再次得到了错误。
错误:请求“连接”中的成员“查询”,这是非类类型的“MYSQL*”
在这一行代码中
// Construct a query object with the query string mysqlpp::Query query =
connection.query(query_string);请帮我找出问题所在?
发布于 2010-09-23 21:55:28
问题是,您必须使用mysql++查询对象来执行查询,而不是使用ostringstream流。ostringstream流只允许您构建查询字符串,但不允许您执行查询。
有一个教程在:http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#simple中显示了基本用法
要从代码获得工作的查询,需要将动态查询转换为字符串,并使用它构造mysql++查询对象。
// todo: create the connection here
// Construct the query string. You were already doing this in your code
std::ostringstream query_builder;
query_builder << "select pipe_id from pipe where version_id='" << id << "'";
// Convert the ostringstream to a string
std::string query_string = query_builder.str();
// Construct a query object with the query string
mysqlpp::Query query = connection.query(query_string);
// Perform the query
mysqlpp::StoreQueryResult result = query.store();
for(size_t i = 0; i < result.num_rows(); i++)
std::cout << result[i]["version_id"] << result[i]["pipe_id"] << std::endl;https://stackoverflow.com/questions/3781880
复制相似问题