简体   繁体   English

从stdin复制无法使用libpqxx在C ++中插入postgres

[英]copy from stdin not working for inserting in postgres in C++ using libpqxx

I have been trying to insert bulk data using copy from stdin but it isn't working. 我一直在尝试使用来自stdin的副本插入批量数据,但是它不起作用。 Can anyone tell me what I am doing wrong: 谁能告诉我我在做什么错:

// 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

I don't find the data which I try to insert inside the table. 我找不到要插入表中的数据。

I don't see where you are actually passing the data to libpqxx. 我看不到您实际将数据传递到libpqxx的位置。 For information on how to do this, please see the ligpqxx documentation on tablestreams. 有关如何执行此操作的信息,请参阅表流上的ligpqxx文档。 http://pqxx.org/devprojects/libpqxx/doc/3.1/html/Reference/a00100.html http://pqxx.org/devprojects/libpqxx/doc/3.1/html/Reference/a00100.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM