我正在努力完成this ,并且我知道如何间接地做到这一点...如果我可以获得表的架构。
我如何使用 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';
}
但只打印“选项卡”。
我也尝试过这个,来自 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的成员。
最佳答案
我发现以下代码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;
最后打印的内容是列的正确名称。
关于c++ - 如何获取社会表的模式或行名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42585140/