简体   繁体   English

SOCI:如何处理许多列?

[英]SOCI: How to deal with many columns?

I'm using SOCI to access a PostgreSQL database. 我正在使用SOCI访问PostgreSQL数据库。 One particular table that I'm inserting into and selecting from has (at present) 72 columns. 我要插入的一个特定表(目前)有72列。 My question is how does one best deal with so many columns? 我的问题是,如何最好地处理这么多列?

I've determined that for selecting, using the SOCI dynamic result set is probably best. 我确定对于选择而言,使用SOCI动态结果集可能是最好的。 In this way I can loop over the columns. 这样,我可以遍历各列。

However, for inserting I'm having difficulty. 但是,插入时遇到困难。 What I want to achieve is something as follows: 我要实现的目标如下:

int vals[NUM_VALS];
statement st = s.prepare << "INSERT INTO table (c0, c1, c2, ...) VALUES (";
for(int i = 0; i < NUM_VALS; ++i)
    st << vals[i];
st << ")";
st.execute();

Is anything like this possible? 这样有可能吗? I've had no luck finding any way of dealing with large numbers of columns in an easy way. 我没有运气找到任何一种简单的方式来处理大量列的方法。

The SOCI-users mailing list provided me with the answer. SOCI用户的邮件列表为我提供了答案。 Deferred construction of the statement object is required. 需要延迟构造语句对象。 For example, to make the above work, change it to: 例如,要使上述工作生效,请将其更改为:

int vals[NUM_VALS];
auto temp = (s.prepare << "INSERT INTO table (c0, c1, c2, ...) VALUES (:c1, :c2, ...)");
for(int i = 0; i < NUM_VALS; ++i)
    temp , into(vals[i]);
statement st(temp).execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM