簡體   English   中英

Soci逐行打印出所有數據

[英]Soci print out all data in table by rows

在不了解架構的情況下,我該如何做? 這是我到目前為止:

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
}

我是這樣做的,它按列打印出來:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM