summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2006-11-24 23:07:07 +0000
committerTom Lane2006-11-24 23:07:07 +0000
commite53a43bf1710533028c4e57df5c0322281827779 (patch)
tree02cb489f16ff2ea624d6ab1b8af047ebaaefeec7
parent8637cd1ee87b0436b0f72bf3179e4600429dbf7d (diff)
Fix psql's \copy command to ensure that it cycles libpq back to the idle state
(in particular, causing the ReadyForQuery message to be eaten) before returning from do_copy. The only known consequence of failing to do so is that get_prompt might show a wrong result for the %x transaction status escape, as reported by Bernd Helmle; but it's possible there are other issues. Back-patch as far as 7.4, the oldest version supporting %x.
-rw-r--r--src/bin/psql/copy.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index aed8b3196ae..925940e84d4 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.33.4.1 2004/08/14 22:24:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.33.4.2 2006/11/24 23:07:07 tgl Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
@@ -416,6 +416,18 @@ do_copy(const char *args)
PQclear(result);
+ /*
+ * Make sure we have pumped libpq dry of results; else it may still be
+ * in ASYNC_BUSY state, leading to false readings in, eg, get_prompt().
+ */
+ while ((result = PQgetResult(pset.db)) != NULL)
+ {
+ success = false;
+ psql_error("\\copy: unexpected response (%d)\n",
+ PQresultStatus(result));
+ PQclear(result);
+ }
+
if (copystream != stdout && copystream != stdin)
fclose(copystream);
free_copy_options(options);