Soci print out all data in table by rows

我与影子孤独终老i 提交于 2019-12-11 05:15:33

问题


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
}

回答1:


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;
    }


来源:https://stackoverflow.com/questions/42493927/soci-print-out-all-data-in-table-by-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!