Fixed psql's Control-C handling when COPY in progress
This commit is contained in:
parent
fc8e6c7746
commit
c8009959c9
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.16 2000/02/20 14:28:20 petere Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.17 2000/02/21 19:40:41 petere Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -246,6 +246,11 @@ volatile bool cancel_pressed;
|
|||||||
void
|
void
|
||||||
handle_sigint(SIGNAL_ARGS)
|
handle_sigint(SIGNAL_ARGS)
|
||||||
{
|
{
|
||||||
|
cancel_pressed = true;
|
||||||
|
|
||||||
|
if (copy_state)
|
||||||
|
return;
|
||||||
|
|
||||||
if (cancelConn == NULL)
|
if (cancelConn == NULL)
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
siglongjmp(main_loop_jmp, 1);
|
siglongjmp(main_loop_jmp, 1);
|
||||||
@ -253,8 +258,6 @@ handle_sigint(SIGNAL_ARGS)
|
|||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cancel_pressed = true;
|
|
||||||
|
|
||||||
/* Try to send cancel request */
|
/* Try to send cancel request */
|
||||||
if (PQrequestCancel(cancelConn))
|
if (PQrequestCancel(cancelConn))
|
||||||
write_stderr("\nCancel request sent\n");
|
write_stderr("\nCancel request sent\n");
|
||||||
@ -297,6 +300,9 @@ PSQLexec(const char *query)
|
|||||||
|
|
||||||
cancelConn = pset.db;
|
cancelConn = pset.db;
|
||||||
res = PQexec(pset.db, query);
|
res = PQexec(pset.db, query);
|
||||||
|
if (PQresultStatus(res) == PGRES_COPY_IN ||
|
||||||
|
PQresultStatus(res) == PGRES_COPY_OUT)
|
||||||
|
copy_state = true;
|
||||||
cancelConn = NULL;
|
cancelConn = NULL;
|
||||||
|
|
||||||
if (PQstatus(pset.db) == CONNECTION_BAD)
|
if (PQstatus(pset.db) == CONNECTION_BAD)
|
||||||
@ -388,6 +394,9 @@ SendQuery(const char *query)
|
|||||||
|
|
||||||
cancelConn = pset.db;
|
cancelConn = pset.db;
|
||||||
results = PQexec(pset.db, query);
|
results = PQexec(pset.db, query);
|
||||||
|
if (PQresultStatus(results) == PGRES_COPY_IN ||
|
||||||
|
PQresultStatus(results) == PGRES_COPY_OUT)
|
||||||
|
copy_state = true;
|
||||||
cancelConn = NULL;
|
cancelConn = NULL;
|
||||||
|
|
||||||
if (results == NULL)
|
if (results == NULL)
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.10 2000/02/16 13:15:26 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.11 2000/02/21 19:40:41 petere Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "copy.h"
|
#include "copy.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <signal.h>
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <unistd.h> /* for isatty */
|
#include <unistd.h> /* for isatty */
|
||||||
#else
|
#else
|
||||||
@ -17,6 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
|
#include "pqsignal.h"
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -26,6 +28,8 @@
|
|||||||
#define strcasecmp(x,y) stricmp(x,y)
|
#define strcasecmp(x,y) stricmp(x,y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool copy_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* parse_slash_copy
|
* parse_slash_copy
|
||||||
* -- parses \copy command line
|
* -- parses \copy command line
|
||||||
@ -358,7 +362,9 @@ handleCopyOut(PGconn *conn, FILE *copystream)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush(copystream);
|
fflush(copystream);
|
||||||
return !PQendcopy(conn);
|
ret = !PQendcopy(conn);
|
||||||
|
copy_state = false;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -386,6 +392,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
char *s;
|
char *s;
|
||||||
int bufleft;
|
int bufleft;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (prompt) /* disable prompt if not interactive */
|
if (prompt) /* disable prompt if not interactive */
|
||||||
{
|
{
|
||||||
@ -435,5 +442,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
}
|
}
|
||||||
PQputline(conn, "\n");
|
PQputline(conn, "\n");
|
||||||
}
|
}
|
||||||
return !PQendcopy(conn);
|
ret = !PQendcopy(conn);
|
||||||
|
copy_state = false;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.7 2000/02/16 13:15:26 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.8 2000/02/21 19:40:42 petere Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef COPY_H
|
#ifndef COPY_H
|
||||||
#define COPY_H
|
#define COPY_H
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
|
|
||||||
|
extern bool copy_state;
|
||||||
|
|
||||||
/* handler for \copy */
|
/* handler for \copy */
|
||||||
bool do_copy(const char *args);
|
bool do_copy(const char *args);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user