Skip to content

Commit 47d6d44

Browse files
committed
Abort a FETCH_COUNT-controlled query if we observe any I/O error on the
output stream. This typically indicates that the user quit out of $PAGER, or that we are writing to a file and ran out of disk space. In either case we shouldn't bother to continue fetching data. Stephen Frost
1 parent ece869b commit 47d6d44

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/bin/psql/common.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.144 2010/02/16 22:34:50 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.145 2010/05/28 20:02:32 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -982,6 +982,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
982982
char fetch_cmd[64];
983983
instr_time before,
984984
after;
985+
int flush_error;
985986

986987
*elapsed_msec = 0;
987988

@@ -1045,6 +1046,9 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
10451046
}
10461047
}
10471048

1049+
/* clear any pre-existing error indication on the output stream */
1050+
clearerr(pset.queryFout);
1051+
10481052
for (;;)
10491053
{
10501054
if (pset.timing)
@@ -1096,19 +1100,29 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
10961100

10971101
printQuery(results, &my_popt, pset.queryFout, pset.logfile);
10981102

1099-
/*
1100-
* Make sure to flush the output stream, so intermediate results are
1101-
* visible to the client immediately.
1102-
*/
1103-
fflush(pset.queryFout);
1103+
PQclear(results);
11041104

11051105
/* after the first result set, disallow header decoration */
11061106
my_popt.topt.start_table = false;
11071107
my_popt.topt.prior_records += ntuples;
11081108

1109-
PQclear(results);
1109+
/*
1110+
* Make sure to flush the output stream, so intermediate results are
1111+
* visible to the client immediately. We check the results because
1112+
* if the pager dies/exits/etc, there's no sense throwing more data
1113+
* at it.
1114+
*/
1115+
flush_error = fflush(pset.queryFout);
11101116

1111-
if (ntuples < pset.fetch_count || cancel_pressed)
1117+
/*
1118+
* Check if we are at the end, if a cancel was pressed, or if
1119+
* there were any errors either trying to flush out the results,
1120+
* or more generally on the output stream at all. If we hit any
1121+
* errors writing things to the stream, we presume $PAGER has
1122+
* disappeared and stop bothering to pull down more data.
1123+
*/
1124+
if (ntuples < pset.fetch_count || cancel_pressed || flush_error ||
1125+
ferror(pset.queryFout))
11121126
break;
11131127
}
11141128

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy