我正在尝试实现this,我知道如何做到这一点,indirectly...if我可以得到一个表的模式。
我如何使用soci来做这件事?
我试过了:
std::string i;
soci::statement st = (mSql->prepare <<
"show create table tab;",
soci::into(i));
st.execute();
while (st.fetch())
{
std::cout << i <<'\n';
}但是只有"tab“被打印出来。
我也试过了,取自GitHub中的Soci文档:
soci::column_info ci;
soci::statement st = (mSql->prepare_column_descriptions(table_name), into(ci));
st.execute();
while (st.fetch())
{
// ci fields describe each column in turn
}但被告知column_info不是soci的成员。
发布于 2017-03-04 04:20:13
我找到了下面的代码here
soci::row v;
soci::statement st = (mSql->prepare << "SELECT * FROM tab", into(v));
st.execute(true); /* with data exchange */
unsigned int num_fields = v.size();
std::cout << "fields: " << num_fields << std::endl;
num_fields = (num_fields <= 9) ? num_fields : 9;
unsigned long num_rows = (unsigned long)st.get_affected_rows();
std::cout << "rows: " << num_rows << std::endl;
for (size_t i = 0; i < num_fields; ++i) {
const soci::column_properties &props = v.get_properties(i);
std::cout << props.get_name() << '\t';
}
std::cout << std::endl;最后打印的是列的正确名称。
https://stackoverflow.com/questions/42585140
复制相似问题