c++ - libpqxx 库中没有 pqxx::tuple 吗?

标签 c++ postgresql c++11 linker libpqxx

已经安装了最新的 ubuntu,并且已经完成:

sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpqxx-4.0v5
sudo apt-get install libpqxx-dev

我无法编译使用 pqxx::tuple 的程序。

编译:

g++ test.cpp -I/usr/local/include/ -lpqxx -lpq
or
g++ test.cpp -lpqxx -lpq -o test

控制台输出:

test.cpp: In function ‘int main()’:
test.cpp:15:21: error: ‘tuple’ in namespace ‘pqxx’ does not name a type
const pqxx::tuple row = r[rownum];

这是有问题的行:

const pqxx::tuple row = r[rownum];

当我删除这一行时,程序可以正常工作。

#include <iostream>
#include <pqxx/pqxx>
int main()
{
  try {
    pqxx::connection c("dbname=mydb user=postgres port=5432 password=*** hostaddr=127.0.0.1");
    pqxx::work w(c);
    pqxx::result r = w.exec("SELECT * FROM get_player_data_function()");
    w.commit();
    const int num_rows = r.size();
    for (int rownum=0; rownum < num_rows; ++rownum) {
        const pqxx::tuple row = r[rownum];
    }
  }
  catch (const std::exception &e) {
    std::cerr << e.what() << std::endl;
  }
}

最佳答案

不确定...但如果我理解正确的话this page ,您必须将 pqxx::tuple 替换为 pqxx::row

所以,我想

const pqxx::row row = r[rownum];

关于c++ - libpqxx 库中没有 pqxx::tuple 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44356646/

相关文章:

c++ - 当两个shared_pointer实例被删除时,删除由两个shared_pointer实例管理的对象

c++ - 为什么这个互斥代码没有按预期工作?

postgresql - 从 Azure CLI(不是 ARC)创建 PostgreSQL 超大规模 Citus DB

c++ - C++11 中的高阶函数

c++ - 文件之间的前向声明

python - 在 PostgreSQL 中计算给定 GPS 坐标的日出和日落时间

performance - 清理和分析 : Drastic change in query cost

c++ - 与 (N)RVO 一起有效使用 move 语义

c++ - 当传递的内存指针不足时放置新的

c++ - 如何正确实现 -> 和 (*)。这样它们的行为就像 -> 和 (*)。在迭代器中