我如何获得Soci中表格的模式或行名称



我正在尝试实现这一目标,我知道如何间接地做...如果我可以获得表格。

我该如何使用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的成员。

我在此处找到以下代码

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;

最后打印的是列的正确名称。

相关内容

  • 没有找到相关文章

最新更新