gpt4 book ai didi

c++ - SOCI c++ 数据库访问库的 boost 元组行集问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:33:26 25 4
gpt4 key购买 nike

在最新的 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/添加括号 社会::行集>行 = (sql.prepare << "从城市中选择 x(位置),y(位置)");

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

最佳答案

你试过添加这个标题吗?

#include <boost-tuple.h>

或者,您可以使用:

#define SOCI_USE_BOOST

在包含 soci.h 之前

关于c++ - SOCI c++ 数据库访问库的 boost 元组行集问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9064898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com