使用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
知道是什么原因吗?
非常感谢!Ludovic
一个解决方案是
1/添加括号soci::rowset>行=(sql.prepare<<"从城市中选择x(位置),y(位置)");
2/做建议的答案:#include或#define
您尝试添加此标头了吗?
#include <boost-tuple.h>
或者,您可以使用:
#define SOCI_USE_BOOST
包括soci.h 之前
相关文章:
- C++:TypeDef使用元组
- Pybind11:将元组列表从Python传递到C++
- 重载元组索引运算符-C++
- 在C++中,如何通过几种类型从元组中选择多个元素
- 将fold表达式与std::一起用于两个元组
- std::ranges::elements_view,用于自定义类似元组的数据
- 将元组的向量转换/构造为堆
- 专用于 std 元组的模板,而无需用户执行remove_cvref
- 将元组的向量构造成堆
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 将元组类型扩展为可变参数模板?
- 时间复杂度 当具有复合数据类型(如元组或对)时?
- 使用函数的元组返回多个值的问题
- 检查是否所有 std::元组元素都满足条件 + 设计问题
- c++在存储指针元组时遇到问题
- 使用SOCI c++数据库访问库的提升元组行集出现问题
- boost元组导致boost绑定/boost函数出现问题
- c++元组链接问题:未定义的引用
- 编译问题:使用元组构建Composite_Key可变模板类
- 元组和可变参数模板的编译问题