Dept. of second thoughts: if query fails part way through, shut down
authorTom Lane
Tue, 29 Aug 2006 22:48:55 +0000 (22:48 +0000)
committerTom Lane
Tue, 29 Aug 2006 22:48:55 +0000 (22:48 +0000)
the pager before reporting the error.

src/bin/psql/common.c

index 87e5ebc1fdd3ef2f102b98dbe2452eaf2e725b4e..81323ad0d63dcbe8b548492ec97cbb9ea64b1533 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.127 2006/08/29 22:25:07 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.128 2006/08/29 22:48:55 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -1062,8 +1062,6 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
 
        /* get FETCH_COUNT tuples at a time */
        results = PQexec(pset.db, fetch_cmd);
-       OK = AcceptResult(results) &&
-           (PQresultStatus(results) == PGRES_TUPLES_OK);
 
        if (pset.timing)
        {
@@ -1071,8 +1069,19 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
            *elapsed_msec += DIFF_MSEC(&after, &before);
        }
 
-       if (!OK)
+       if (PQresultStatus(results) != PGRES_TUPLES_OK)
        {
+           /* shut down pager before printing error message */
+           if (did_pager)
+           {
+               ClosePager(pset.queryFout);
+               pset.queryFout = queryFout_copy;
+               pset.queryFoutPipe = queryFoutPipe_copy;
+               did_pager = false;
+           }
+
+           OK = AcceptResult(results);
+           psql_assert(!OK);
            PQclear(results);
            break;
        }