Home » U++ Library support » U++ SQL » Copy from stdin (PostgreSQL) support in U++ SQL
Copy from stdin (PostgreSQL) support in U++ SQL [message #53427] |
Thu, 02 April 2020 20:41 |
shutalker
Messages: 15 Registered: November 2017 Location: Moscow
|
Promising Member |
|
|
Hi all!
Is it possible to execute COPY table_name FROM STDIN via Sql interface?
I'm trying to do something like this
PostgreSQLSession pgSession;
if (!pgSession.Open("dbname=postgres user=postgres")) {
RLOG("failed to setup postgresql session");
return;
}
Sql sql(pgSession);
// Is there a way to setup any IO stream for data transfer?
if (!sql.Execute("COPY my_test_table FROM STDIN")) {
RLOG("failed to copy data from client: " << sql.GetLastError());
return;
}
But I don't know how to transfer data I want to import into database.
UPD: I've made a temporary dirty hack that works. This hack requires psql client to be installed
...
LocalProcess psqlClient;
String psqlCopyCmd = Format("\\COPY \"%s\" FROM STDIN", tableName);
if (!psqlClient.Start("psql", {config["database"]["init"], "-c", psqlCopyCmd}))
throw String("failed to run psql client in child process");
...
String copyLine;
...
psqlClient.Write(copyLine);
...
psqlClient.CloseWrite();
String exitMessage;
psqlClient.Finish(exitMessage);
if (psqlClient.GetExitCode() != 0)
throw Format("failed to import 3d-data into database: %s", exitMessage);
...
[Updated on: Fri, 03 April 2020 14:35] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Apr 27 23:06:56 CEST 2024
Total time taken to generate the page: 0.04899 seconds
|