帮助我,我想做一个通用的函数,得到任何查询字符串的结果,并把所有行到另一个变量。当迭代一行时,我如何知道可用的列数?
Environment *env = Environment::createEnvironment();
Connection *conn = env->createConnection("user","pass");
quantLinhas = 0;
if( conn != NULL ) {
Statement *stmt = conn->createStatement(query);
ResultSet *rs = stmt->executeQuery();
resultadoSQL->linhas.clear();
while (rs->next()) {
aux.campos.clear();
numbers_colums = rs->whatever_method() //WHAT DO I DO HERE??
for(i = 0; i < numbers_colums ; i++) {
aux.campos.push_back( rs->getString(i) );
quantLinhas++;
}
resultadoSQL->linhas.push_back( aux );
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
}
根据文档,您可以使用getColumnListMetaData
函数。返回向量中的元素个数可能是您想要的。您可以检查每个元素是否为PTYPE_COL以确保它。
try this
vector<MetaData> columnList = rs->getColumnListMetaData();
numbers_colums = columnList.size();
columnList.clear();
它对我有效。源链接