c++ - soci按行打印出表格中的所有数据

标签 c++ mysql sql soci

在不知道模式的情况下,我该怎么做呢?这是我目前所拥有的:

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

关于c++ - soci按行打印出表格中的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42493927/

相关文章:

c++ - 指向字符串和 strcmp 的指针

php - 从 Propel 的结果集中排除连接关系对象的方法?

sql检查2列中的逻辑错误

MySQL日期格式更改

c# - 将日期时间作为包含数量字段的列的 SQL 透视

c++ - 以十六进制打印数据结构值

c++ - 从 float array 到 mat ,连接图像 block

c++ - 从 DWORD 中提取 lo 和 hi 字时为什么需要二进制移位?

mysql - Hive 连接到 MySQL : Access denied for user 'hive' @'localhost' hive

mysql - 无法理解。这是子查询吗?