Skip to content

Commit a164208

Browse files
committed
Fixed deficiency where an unterminated (no semicolon) command at end of
psql script would be dropped silently.
1 parent e631df3 commit a164208

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/bin/psql/mainloop.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.24 2000/03/05 13:30:19 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.25 2000/03/13 13:46:32 petere Exp $
77
*/
88
#include "postgres.h"
99
#include "mainloop.h"
@@ -61,7 +61,7 @@ MainLoop(FILE *source)
6161
bool prev_cmd_interactive;
6262

6363
unsigned int prev_lineno;
64-
bool die_on_error;
64+
volatile bool die_on_error = false;
6565

6666

6767
/* Save old settings */
@@ -395,6 +395,7 @@ MainLoop(FILE *source)
395395
appendPQExpBufferChar(query_buf, '\n');
396396
/* append the line to the query buffer */
397397
appendPQExpBufferStr(query_buf, line + query_start);
398+
appendPQExpBufferChar(query_buf, ';');
398399
}
399400

400401
/* execute query */
@@ -515,8 +516,21 @@ MainLoop(FILE *source)
515516
successResult = EXIT_BADCONN;
516517
break;
517518
}
518-
} /* while !endofprogram */
519-
519+
} /* while !endoffile/session */
520+
521+
/*
522+
* Process query at the end of file without a semicolon
523+
*/
524+
if (query_buf->len > 0 && !pset.cur_cmd_interactive)
525+
{
526+
success = SendQuery(query_buf->data);
527+
528+
if (!success && die_on_error)
529+
successResult = EXIT_USER;
530+
else if (pset.db == NULL)
531+
successResult = EXIT_BADCONN;
532+
}
533+
520534
destroyPQExpBuffer(query_buf);
521535
destroyPQExpBuffer(previous_buf);
522536

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