簡體   English   中英

使用SOCI C ++數據庫訪問庫的增強元組行集的問題

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

將元組的行集與最新的soci和boost庫一起使用時,出現編譯錯誤。

我在網上找到了一個示例,但是它不能與我使用的SOCI版本一起編譯,而這是最新版本。

引起問題的部分是這個:

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

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

這是我從網上示例獲得的完整代碼:

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

}

它在以下行中失敗:

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

這是我不太了解的錯誤:

   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

知道可能是什么原因嗎?

非常感謝! 朱利


一個解決方案是

1 /添加括號soci :: rowset>行=(sql.prepare <<“從城市中選擇x(位置),y(位置)”);

2 /做建議的答案:#include或#define

您是否嘗試過添加此標頭?

#include <boost-tuple.h>

或者,您可以使用:

#define SOCI_USE_BOOST

在包含soci.h之前

暫無
暫無

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

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