我读了Poco::Data User Manual并且提到该库支持多个结果集。 Multiple Data Sets 中有此支持的示例手册的一部分。
typedef Tuple<std::string, std::string, std::string, int> Person;
Person pHomer, pLisa;
int aHomer(42), aLisa(10), aBart(0);
session << "SELECT * FROM Person WHERE Age = ?; "
"SELECT Age FROM Person WHERE FirstName = 'Bart'; "
"SELECT * FROM Person WHERE Age = ?",
into(pHomer, 0), use(aHomer),
into(aBart, 1),
into(pLisa, 2), use(aLisa),
now;
但此示例仅适用于使用库获取数据的一种支持方式。 RecordSets, Iterators and Rows 中有第二种获取数据的方法部分。
Statement select(session); // we need a Statement for later RecordSet creation
select << "SELECT * FROM Person", now;
// create a RecordSet
RecordSet rs(select);
std::size_t cols = rs.columnCount();
// print all column names
for (std::size_t col = 0; col < cols; ++col)
std::cout << rs.columnName(col) << std::endl;
// iterate over all rows and columns
for (RecordSet::Iterator it = rs.begin(); it != rs.end(); ++it)
std::cout << *it << " ";
我有一个围绕 Poco::Data 的包装器,它使用第二种方式获取数据,我必须扩展它以支持多个结果集。我想知道是否有可能以及如何使用 RecordSet 接口(interface)获取多个结果集?
后记:
多个结果集是存储过程调用的结果,因此,不可能只为每个选择使用多个 Statement 对象。
最佳答案
在单个语句中处理从存储过程返回的多个结果集是完全可能的。见例如。 this test (执行 here );缺点是您必须预先知道返回的数据是什么样的,这与 RecordSet 不同,RecordSet 是通用的,可以提供输出而无需事先了解返回的数据结构。
遗憾的是,目前无法使用 RecordSet 访问多个数据集。但是,由于 RecordSet is implemented in terms of Statement ,添加这样的功能应该不会太难。
希望这对您有所帮助。
关于c++ - 如何使用 Poco::Data 获取多个结果集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743404/