0

I have been trying to insert bulk data using copy from stdin but it isn't working. 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.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
NewAlgo
  • 31
  • 1
  • 3

1 Answers1

0

I don't see where you are actually passing the data to libpqxx. For information on how to do this, please see the ligpqxx documentation on tablestreams. http://pqxx.org/devprojects/libpqxx/doc/3.1/html/Reference/a00100.html

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
  • tablestreams are deprecated in the latest version of pqxx. Is there a replacement? – ty. Jan 28 '14 at 17:54