diff options
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r-- | src/bin/psql/common.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 3a820faf78f..6ca9bbc9d86 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -628,7 +628,7 @@ StoreQueryTuple(const PGresult *result) * command. In that event, we'll marshal data for the COPY and then cycle * through any subsequent PGresult objects. * - * When the command string contained no affected COPY command, this function + * When the command string contained no such COPY command, this function * degenerates to an AcceptResult() call. * * Changes its argument to point to the last PGresult of the command string, @@ -688,13 +688,28 @@ ProcessResult(PGresult **results) * Marshal the COPY data. Either subroutine will get the * connection out of its COPY state, then call PQresultStatus() * once and report any error. + * + * If pset.copyStream is set, use that as data source/sink, + * otherwise use queryFout or cur_cmd_source as appropriate. */ + FILE *copystream = pset.copyStream; + SetCancelConn(); if (result_status == PGRES_COPY_OUT) - success = handleCopyOut(pset.db, pset.queryFout) && success; + { + if (!copystream) + copystream = pset.queryFout; + success = handleCopyOut(pset.db, + copystream) && success; + } else - success = handleCopyIn(pset.db, pset.cur_cmd_source, + { + if (!copystream) + copystream = pset.cur_cmd_source; + success = handleCopyIn(pset.db, + copystream, PQbinaryTuples(*results)) && success; + } ResetCancelConn(); /* |