diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-24 23:07:01 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-11-24 23:07:01 +0000 |
commit | fc821135fbbcd23d8675985465da2f07b45be93b (patch) | |
tree | 06158be52a0076ecb461e2d5b0d3ed89aa1d5f91 /src | |
parent | db8a3fd68038907efb47d0ad3de5e037c9594b7c (diff) | |
download | postgresql-fc821135fbbcd23d8675985465da2f07b45be93b.tar.gz postgresql-fc821135fbbcd23d8675985465da2f07b45be93b.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/copy.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 9b6d9144450..572dcd1b717 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.55 2005/01/01 05:43:08 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.55.4.1 2006/11/24 23:07:01 tgl Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -568,6 +568,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 (options->file != NULL) { if (fclose(copystream) != 0) |