2013-09-24 2 views
0

stdin의 복사본을 사용하여 대량 데이터를 삽입하려고했지만 작동하지 않습니다. 는 아무도 내가 뭘 잘못 말해 줄 수 :stdin의 복사본이 libpqxx를 사용하는 C++의 postgres에 삽입되지 않습니다.

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

나는 테이블 내부에 삽입 할 데이터를 찾을 수 없습니다.

답변

0

실제로 데이터를 libpqxx에 전달하는 위치가 표시되지 않습니다. 이를 수행하는 방법에 대한 정보는 tablestreams에있는 ligpqxx 문서를 참조하십시오. http://pqxx.org/devprojects/libpqxx/doc/3.1/html/Reference/a00100.html

+0

tablestreams는 최신 버전의 pqxx에서 더 이상 사용되지 않습니다. 대체품이 있습니까? –