33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.17 2000/02/21 19:40:41 petere Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.18 2000/03/01 21:09:58 petere Exp $
77 */
88#include "postgres.h"
99#include "common.h"
@@ -170,6 +170,8 @@ NoticeProcessor(void * arg, const char * message)
170170 *
171171 * Returns a malloc()'ed string with the input (w/o trailing newline).
172172 */
173+ static bool prompt_state ;
174+
173175char *
174176simple_prompt (const char * prompt ,int maxlen ,bool echo )
175177{
@@ -187,6 +189,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
187189if (prompt )
188190fputs (prompt ,stderr );
189191
192+ prompt_state = true;
193+
190194#ifdef HAVE_TERMIOS_H
191195if (!echo )
192196{
@@ -207,6 +211,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
207211}
208212#endif
209213
214+ prompt_state = false;
215+
210216length = strlen (destination );
211217if (length > 0 && destination [length - 1 ]!= '\n' )
212218{
@@ -238,32 +244,28 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
238244 * facilities in a signal handler.
239245 */
240246
241- static PGconn * cancelConn ;
247+ PGconn * cancelConn ;
242248volatile bool cancel_pressed ;
243249
244250#define write_stderr (String ) write(fileno(stderr), String, strlen(String))
245251
246252void
247253handle_sigint (SIGNAL_ARGS )
248254{
249- cancel_pressed = true;
250-
251- if (copy_state )
255+ /* Don't muck around if copying in or prompting for a password. */
256+ if ((copy_in_state && pset .cur_cmd_interactive )|| prompt_state )
252257return ;
253258
254259if (cancelConn == NULL )
255- #ifndef WIN32
256260siglongjmp (main_loop_jmp ,1 );
257- #else
258- return ;
259- #endif
260261
261- /* Try to send cancel request */
262+ cancel_pressed = true;
263+
262264if (PQrequestCancel (cancelConn ))
263- write_stderr ("\nCancel request sent\n" );
265+ write_stderr ("Cancel request sent\n" );
264266else
265267{
266- write_stderr ("\nCould not send cancel request: " );
268+ write_stderr ("Could not send cancel request: " );
267269write_stderr (PQerrorMessage (cancelConn ));
268270}
269271}
@@ -300,10 +302,11 @@ PSQLexec(const char *query)
300302
301303cancelConn = pset .db ;
302304res = PQexec (pset .db ,query );
303- if (PQresultStatus (res )== PGRES_COPY_IN ||
304- PQresultStatus (res )== PGRES_COPY_OUT )
305- copy_state = true;
306- cancelConn = NULL ;
305+ if (PQresultStatus (res )== PGRES_COPY_IN )
306+ copy_in_state = true;
307+ /* keep cancel connection for copy out state */
308+ if (PQresultStatus (res )!= PGRES_COPY_OUT )
309+ cancelConn = NULL ;
307310
308311if (PQstatus (pset .db )== CONNECTION_BAD )
309312{
@@ -394,10 +397,11 @@ SendQuery(const char *query)
394397
395398cancelConn = pset .db ;
396399results = PQexec (pset .db ,query );
397- if (PQresultStatus (results )== PGRES_COPY_IN ||
398- PQresultStatus (results )== PGRES_COPY_OUT )
399- copy_state = true;
400- cancelConn = NULL ;
400+ if (PQresultStatus (results )== PGRES_COPY_IN )
401+ copy_in_state = true;
402+ /* keep cancel connection for copy out state */
403+ if (PQresultStatus (results )!= PGRES_COPY_OUT )
404+ cancelConn = NULL ;
401405
402406if (results == NULL )
403407{