Soci按行打印出表中的所有数据 [英] Soci print out all data in table by rows

查看:104
本文介绍了Soci按行打印出表中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不了解架构的情况下,我该如何做?这是我到目前为止的内容:

Without knowing the schema, how can I do the above? This is what I have so far:

row r;
soci::statement st = (mSql->prepare <<
                "select * from tab",
                soci::into(r));

st.execute();
while (st.fetch())
{
        //want a way to print each row
}

推荐答案

我做到了,它按列显示:

I did it like this, and it prints out by column:

    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::string s = (std::string)props.get_name();
            int row;
            soci::statement st = (mSql->prepare << "select " << props.get_name().c_str() <<" from map", soci::into(row));
            st.execute();
            while (st.fetch())
            {
                    std::stringstream ss;
                    ss << row;
                    std::string str = ss.str();
                    cout<<str<<" ";
            }
            cout<<endl;
    }

这篇关于Soci按行打印出表中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆