简体   繁体   English

使用SOCI C ++数据库访问库的增强元组行集的问题

[英]Issue with rowset of boost tuples with SOCI c++ database access library

I have a compilation error when using rowset of tuples with the latest soci and boost libraries. 将元组的行集与最新的soci和boost库一起使用时,出现编译错误。

I found an example on the net but it does not compile with the version of SOCI that I use and which is the latest. 我在网上找到了一个示例,但是它不能与我使用的SOCI版本一起编译,而这是最新版本。

The portion which is causing issue is this one: 引起问题的部分是这个:

typedef std::vector<boost::tuple<double, double> > V;

soci::rowset<boost::tuple<double, double> > rows
        = sql.prepare << "select x(location),y(location) from cities";

Here is the complete code that I got from an example on the net: 这是我从网上示例获得的完整代码:

#include <soci.h>
#include <soci-postgresql.h>
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <boost/timer.hpp>
#include <boost/random.hpp>
#include <boost/tuple/tuple.hpp>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
#include <string>
#include <exception>

int main()
{
    try
    {
        soci::session sql(soci::postgresql, "dbname=ggl user=ggl password=ggl");

    int count;
    sql << "select count(*) from cities", soci::into(count);
    std::cout << "# Capitals: " << count << std::endl;

    typedef std::vector<boost::tuple<double, double> > V;

    soci::rowset<boost::tuple<double, double> > rows
        = sql.prepare << "select x(location),y(location) from cities";
    V vec;
    std::copy(rows.begin(), rows.end(), std::back_inserter(vec));

    for (V::const_iterator it = vec.begin(); it != vec.end(); ++it)
    {
        std::cout << it->get<0>() << " " << it->get<1>() << std::endl;
    }
}
catch (std::exception const &e)
{
    std::cerr << "Error: " << e.what() << '\n';
}
return 0;

} }

It fails on the following line: 它在以下行中失败:

   soci::rowset<boost::tuple<double, double> > rows
            = sql.prepare << "select x(location),y(location) from cities";

And here is the error which I don quite understand: 这是我不太了解的错误:

   g++  -c  "/home/ubuntu/dev/testSoci/test.cpp" -g -O0 -Wall  -o ./Debug/test.o -I./include -I/home/ubuntu/dev/tools/QxOrm/include -I/usr/share/qt4/include -I/home/ubuntu/dev/tools/boost_1_48_0  -I. -I. -I/home/ubuntu/dev/tools/soci-3.1.0/core -I/home/ubuntu/dev/tools/soci-3.1.0/backends/postgresql -I/usr/include/postgresql -I/home/ubuntu/dev/tools/boost_1_48_0/boost 
In file included from /home/ubuntu/dev/tools/soci-3.1.0/core/into-type.h:13,
                 from /home/ubuntu/dev/tools/soci-3.1.0/core/blob-exchange.h:12,
                 from /home/ubuntu/dev/tools/soci-3.1.0/core/soci.h:18,
                 from /home/ubuntu/dev/testSoci/test.cpp:21:
/home/ubuntu/dev/tools/soci-3.1.0/core/exchange-traits.h: In instantiation of ‘soci::details::exchange_traits<boost::tuples::tuple<double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >’:
/home/ubuntu/dev/tools/soci-3.1.0/core/into.h:29:   instantiated from ‘soci::details::into_type_ptr soci::into(T&) [with T = boost::tuples::tuple<double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]’
/home/ubuntu/dev/tools/soci-3.1.0/core/rowset.h:125:   instantiated from ‘soci::details::rowset_impl<T>::rowset_impl(const soci::details::prepare_temp_type&) [with T = boost::tuples::tuple<double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]’
/home/ubuntu/dev/tools/soci-3.1.0/core/rowset.h:185:   instantiated from ‘soci::rowset<T>::rowset(const soci::details::prepare_temp_type&) [with T = boost::tuples::tuple<double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]’
/home/ubuntu/dev/testSoci/test.cpp:51:   instantiated from here
/home/ubuntu/dev/tools/soci-3.1.0/core/exchange-traits.h:34: error: incomplete type ‘soci::details::exchange_traits<boost::tuples::tuple<double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >’ used in nested name specifier
make[1]: *** [Debug/test.o] Error 1

Any idea of what could be the cause? 知道可能是什么原因吗?

Thanks a lot! 非常感谢! Ludovic 朱利


A solution was 一个解决方案是

1/ to add parenthesis soci::rowset > rows = (sql.prepare << "select x(location),y(location) from cities"); 1 /添加括号soci :: rowset>行=(sql.prepare <<“从城市中选择x(位置),y(位置)”);

2/ to do what is proposed as answer: #include or the #define 2 /做建议的答案:#include或#define

Have you tried adding this header? 您是否尝试过添加此标头?

#include <boost-tuple.h>

Alternatively, you can use: 或者,您可以使用:

#define SOCI_USE_BOOST

before including soci.h 在包含soci.h之前

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

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