Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc75adac

Browse files
committed
More fixes for psql ^C handling, especially during copy. Still doesn't
cope so well with copy to but that will have to wait for the next release.Also added -X option to prevent reading .psqlrc startup file.
1 parent19c29f9 commitc75adac

File tree

12 files changed

+121
-70
lines changed

12 files changed

+121
-70
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.26 2000/02/20 14:29:21 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.27 2000/03/01 21:09:56 petere Exp $
33
Postgres documentation
44
-->
55

@@ -1554,6 +1554,16 @@ Access permissions for database "test"
15541554
</varlistentry>
15551555

15561556

1557+
<varlistentry>
1558+
<term>-X, --no-psqlrc</term>
1559+
<listitem>
1560+
<para>
1561+
Do not read the startup file <filename>~/.psqlrc</filename>.
1562+
</para>
1563+
</listitem>
1564+
</varlistentry>
1565+
1566+
15571567
<varlistentry>
15581568
<term>-?, --help</term>
15591569
<listitem>
@@ -2065,7 +2075,7 @@ testdb=> <userinput>\set content `sed -e "s/'/\\\\\\'/g" < my_file.txt`</userinp
20652075
</para>
20662076

20672077
<para>
2068-
Before starting up in interactive mode, <application>psql</application> attempts
2078+
Before starting up, <application>psql</application> attempts
20692079
to read and execute commands from the file <filename>$HOME/.psqlrc</filename>. It
20702080
could be used to set up the client or the server to taste (using the <command>\set
20712081
</command> and <command>SET</command> commands).
@@ -2101,7 +2111,7 @@ $endif
21012111
does not seem to use it, you must make sure that <productname>PostgreSQL</productname>'s
21022112
top-level <filename>configure</filename> script finds it. <filename>configure</filename>
21032113
needs to find both the library <filename>libreadline.a</filename>
2104-
(or<filename>libreadline.so</filename> on systems withsharedlibraries)
2114+
(orasharedlibrary equivalent)
21052115
<emphasis>and</emphasis> the header files <filename>readline.h</filename> and
21062116
<filename>history.h</filename> (or <filename>readline/readline.h</filename> and
21072117
<filename>readline/history.h</filename>) in appropriate directories. If
@@ -2276,6 +2286,15 @@ Field separator is "oo".
22762286
</para>
22772287
</listitem>
22782288

2289+
<listitem>
2290+
<para>
2291+
Pressing Control-C during a <quote>copy in</quote> (data sent to the
2292+
server) doesn't show the most ideal of behaviours. If you get a message
2293+
such as <quote>PQexec: you gotta get out of a COPY state yourself</quote>,
2294+
simply reset the connection by entering <literal>\c - -</literal>.
2295+
</para>
2296+
</listitem>
2297+
22792298
</itemizedlist>
22802299

22812300
</refsect2>

‎src/bin/psql/command.c

Lines changed: 3 additions & 3 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/command.c,v 1.23 2000/02/21 02:05:12 ishii Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.24 2000/03/01 21:09:58 petere Exp $
77
*/
88
#include"postgres.h"
99
#include"command.h"
@@ -432,7 +432,7 @@ exec_command(const char *cmd,
432432
}
433433
else
434434
{
435-
success=process_file(fname)==EXIT_SUCCESS;
435+
success=(process_file(fname)==EXIT_SUCCESS);
436436
free (fname);
437437
}
438438
}
@@ -727,7 +727,7 @@ exec_command(const char *cmd,
727727
elseif (strcmp(cmd,"?")==0)
728728
slashUsage();
729729

730-
#if1
730+
#if0
731731
/*
732732
* These commands don't do anything. I just use them to test the
733733
* parser.

‎src/bin/psql/common.c

Lines changed: 24 additions & 20 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/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+
staticboolprompt_state;
174+
173175
char*
174176
simple_prompt(constchar*prompt,intmaxlen,boolecho)
175177
{
@@ -187,6 +189,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
187189
if (prompt)
188190
fputs(prompt,stderr);
189191

192+
prompt_state= true;
193+
190194
#ifdefHAVE_TERMIOS_H
191195
if (!echo)
192196
{
@@ -207,6 +211,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
207211
}
208212
#endif
209213

214+
prompt_state= false;
215+
210216
length=strlen(destination);
211217
if (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-
staticPGconn*cancelConn;
247+
PGconn*cancelConn;
242248
volatileboolcancel_pressed;
243249

244250
#definewrite_stderr(String) write(fileno(stderr), String, strlen(String))
245251

246252
void
247253
handle_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)
252257
return;
253258

254259
if (cancelConn==NULL)
255-
#ifndefWIN32
256260
siglongjmp(main_loop_jmp,1);
257-
#else
258-
return;
259-
#endif
260261

261-
/* Try to send cancel request */
262+
cancel_pressed= true;
263+
262264
if (PQrequestCancel(cancelConn))
263-
write_stderr("\nCancel request sent\n");
265+
write_stderr("Cancel request sent\n");
264266
else
265267
{
266-
write_stderr("\nCould not send cancel request: ");
268+
write_stderr("Could not send cancel request: ");
267269
write_stderr(PQerrorMessage(cancelConn));
268270
}
269271
}
@@ -300,10 +302,11 @@ PSQLexec(const char *query)
300302

301303
cancelConn=pset.db;
302304
res=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

308311
if (PQstatus(pset.db)==CONNECTION_BAD)
309312
{
@@ -394,10 +397,11 @@ SendQuery(const char *query)
394397

395398
cancelConn=pset.db;
396399
results=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

402406
if (results==NULL)
403407
{

‎src/bin/psql/common.h

Lines changed: 2 additions & 1 deletion
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/common.h,v 1.7 2000/02/20 14:28:20 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.8 2000/03/01 21:09:58 petere Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -29,6 +29,7 @@ void NoticeProcessor(void * arg, const char * message);
2929
char*simple_prompt(constchar*prompt,intmaxlen,boolecho);
3030

3131
externvolatileboolcancel_pressed;
32+
externPGconn*cancelConn;
3233
voidhandle_sigint(SIGNAL_ARGS);
3334

3435
PGresult*PSQLexec(constchar*query);

‎src/bin/psql/copy.c

Lines changed: 13 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/copy.c,v 1.11 2000/02/21 19:40:41 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.12 2000/03/01 21:09:58 petere Exp $
77
*/
88
#include"postgres.h"
99
#include"copy.h"
@@ -28,7 +28,7 @@
2828
#definestrcasecmp(x,y) stricmp(x,y)
2929
#endif
3030

31-
boolcopy_state;
31+
boolcopy_in_state;
3232

3333
/*
3434
* parse_slash_copy
@@ -335,6 +335,8 @@ handleCopyOut(PGconn *conn, FILE *copystream)
335335
charcopybuf[COPYBUFSIZ];
336336
intret;
337337

338+
assert(cancelConn);
339+
338340
while (!copydone)
339341
{
340342
ret=PQgetline(conn,copybuf,COPYBUFSIZ);
@@ -363,7 +365,7 @@ handleCopyOut(PGconn *conn, FILE *copystream)
363365
}
364366
fflush(copystream);
365367
ret= !PQendcopy(conn);
366-
copy_state=false;
368+
cancelConn=NULL;
367369
returnret;
368370
}
369371

@@ -394,6 +396,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
394396
intc=0;
395397
intret;
396398

399+
#ifdefUSE_ASSERT_CHECKING
400+
assert(copy_in_state);
401+
#endif
402+
397403
if (prompt)/* disable prompt if not interactive */
398404
{
399405
if (!isatty(fileno(copystream)))
@@ -409,6 +415,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
409415
}
410416
firstload= true;
411417
linedone= false;
418+
412419
while (!linedone)
413420
{/* for each bufferload in line ... */
414421
s=copybuf;
@@ -427,6 +434,8 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
427434
{
428435
PQputline(conn,"\\.");
429436
copydone= true;
437+
if (pset.cur_cmd_interactive)
438+
puts("\\.");
430439
break;
431440
}
432441
PQputline(conn,copybuf);
@@ -443,6 +452,6 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
443452
PQputline(conn,"\n");
444453
}
445454
ret= !PQendcopy(conn);
446-
copy_state= false;
455+
copy_in_state= false;
447456
returnret;
448457
}

‎src/bin/psql/copy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.8 2000/02/21 19:40:42 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/copy.h,v 1.9 2000/03/01 21:09:58 petere Exp $
77
*/
88
#ifndefCOPY_H
99
#defineCOPY_H
1010

1111
#include"libpq-fe.h"
1212

13-
externboolcopy_state;
13+
externboolcopy_in_state;
1414

1515
/* handler for \copy */
1616
booldo_copy(constchar*args);

‎src/bin/psql/create_help.pl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,33 @@
55
#
66
# Copyright 2000 by PostgreSQL Global Development Group
77
#
8-
# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.4 2000/02/07 23:10:06 petere Exp $
8+
# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.5 2000/03/01 21:09:58 petere Exp $
99
#################################################################
1010

1111
#
1212
# This script automatically generates the help on SQL in psql from
1313
# the SGML docs. So far the format of the docs was consistent
14-
# enough that this worked, but this here ismy no means an SGML
14+
# enough that this worked, but this here isby no means an SGML
1515
# parser.
1616
#
1717
# Call: perl create_help.pl sql_help.h
1818
# The name of the header file doesn't matter to this script, but it
1919
# sure does matter to the rest of the source.
2020
#
21-
# A rule for this is also in the psql makefile.
22-
#
2321

2422
$docdir ="./../../../doc/src/sgml/ref";
25-
$outputfile =$ARGV[0]ordie"Missingrequired argument.\n";
23+
$outputfile =$ARGV[0]ordie"$0: missingrequired argument\n";
2624

2725
$define =$outputfile;
2826
$define =~tr/a-z/A-Z/;
2927
$define =~s/\W/_/g;
3028

31-
opendir DIR,$docdirordie"Couldn't open documentation sources:$!\n";
32-
open OUT,">$outputfile"ordie"Couldn't open output file '$outputfile':$!\n";
29+
opendir DIR,$docdirordie"$0: could not open documentation sources:$!\n";
30+
open OUT,">$outputfile"ordie"$0: could not open output file '$outputfile':$!\n";
3331

3432
print OUT
3533
"/*
36-
* *** Do not change this file directly. Changes will be overwritten. ***
34+
* *** Do not change this file. It is machine-generated. ***
3735
*
3836
* This file was generated by
3937
* $^X$0$outputfile

‎src/bin/psql/help.c

Lines changed: 3 additions & 2 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/help.c,v 1.22 2000/02/20 14:28:20 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.23 2000/03/01 21:09:58 petere Exp $
77
*/
88
#include"postgres.h"
99
#include"help.h"
@@ -124,10 +124,11 @@ usage(void)
124124
env=user;
125125
printf(" -U <username> Specify database username (default: %s)\n",env);
126126

127-
puts(" -x Turn on expanded table output (-P expanded)");
128127
puts(" -v name=val Set psql variable 'name' to 'value'");
129128
puts(" -V Show version information and exit");
130129
puts(" -W Prompt for password (should happen automatically)");
130+
puts(" -x Turn on expanded table output (-P expanded)");
131+
puts(" -X Do not read startup file (~/.psqlrc)");
131132

132133
puts("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\"");
133134
puts("(for SQL commands) from within psql, or consult the psql section in");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp