* 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,
* 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();
/*
{
PQExpBufferData query;
FILE *copystream;
- FILE *save_file;
- FILE **override_file;
struct copy_options *options;
bool success;
- struct stat st;
/* parse options */
options = parse_slash_copy(args);
if (options->from)
{
- override_file = &pset.cur_cmd_source;
-
if (options->file)
{
if (options->program)
}
else
{
- override_file = &pset.queryFout;
-
if (options->file)
{
if (options->program)
if (!options->program)
{
+ struct stat st;
int result;
/* make sure the specified file is not a directory */
if (options->after_tofrom)
appendPQExpBufferStr(&query, options->after_tofrom);
- /* Run it like a user command, interposing the data source or sink. */
- save_file = *override_file;
- *override_file = copystream;
+ /* run it like a user command, but with copystream as data source/sink */
+ pset.copyStream = copystream;
success = SendQuery(query.data);
- *override_file = save_file;
+ pset.copyStream = NULL;
termPQExpBuffer(&query);
if (options->file != NULL)