【问题标题】:copy from stdin not working for inserting in postgres in C++ using libpqxx从标准输入复制不适用于使用 libpqxx 在 C++ 中插入 postgres
【发布时间】:2013-09-24 12:21:53
【问题描述】:

我一直在尝试使用标准输入的副本插入批量数据,但它不起作用。 谁能告诉我我做错了什么:

// Redirecting file input to stdin
std::ifstream in("infile.csv");
std::streambuf *cinbuf = std::cin.rdbuf(); // save old buffer
std::cin.rdbuf(in.rdbuf());     // redirect std::cin to in
std::string copyQuery("COPY tableName (col1,col2) FROM STDIN DELIMITER ',' CSV HEADER");

//Database connection
std::string conninfo("host=ip port=5432 dbname=tdb user=tdbuser password=tdbpsswd);
pqxx::connection conn(conninfo);
pqxx::work transaction(conn);

pqxx::result res = transaction.exec(copyQuery);
transaction.commit();

std::cin.rdbuf(cinbuf); // reset to standard input again

我没有找到我尝试在表格中插入的数据。

【问题讨论】:

    标签: c++ postgresql stdin libpqxx


    【解决方案1】:

    我看不到您将数据实际传递到 libpqxx 的位置。有关如何执行此操作的信息,请参阅 tablestreams 上的 ligpqxx 文档。 http://pqxx.org/devprojects/libpqxx/doc/3.1/html/Reference/a00100.html

    【讨论】:

    • tablestreams 在最新版本的 pqxx 中已被弃用。有替代品吗?
    猜你喜欢
    • 1970-01-01
    • 2020-03-31
    • 2014-12-14
    • 2018-08-31
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多