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

Commitaf00c04

Browse files
committed
Fix psql history handling:
> 1) Fix the problems with the \s command.> When the saveHistory is executed by the \s command we must not do the> conversion \n -> \x01 (per>http://archives.postgresql.org/pgsql-hackers/2006-03/msg00317.php )>> 2) Fix the handling of Ctrl+C>> Now when you do> wsdb=# select 'your long query here '> wsdb-#> and press afterwards the CtrlC the line "select 'your long query here'"> will be in the history>> (partly per>http://archives.postgresql.org/pgsql-hackers/2006-03/msg00297.php )>> 3) Fix the handling of commands with not closed brackets, quotes,double> quotes. (now those commands are not splitted in parts...)>> 4) Fix the behaviour when SINGLELINE mode is used. (before it wasalmost> broken ;(Sergey E. Koposov
1 parent3b7e2b1 commitaf00c04

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

‎src/bin/psql/command.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.164 2006/03/05 15:58:51 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.165 2006/03/21 13:38:11 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -753,7 +753,7 @@ exec_command(const char *cmd,
753753

754754
expand_tilde(&fname);
755755
/* This scrolls off the screen when using /dev/tty */
756-
success=saveHistory(fname ?fname :DEVTTY);
756+
success=saveHistory(fname ?fname :DEVTTY, false);
757757
if (success&& !quiet&&fname)
758758
printf(gettext("Wrote history to file \"%s/%s\".\n"),
759759
pset.dirname ?pset.dirname :".",fname);

‎src/bin/psql/input.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.52 2006/03/06 04:45:21 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.53 2006/03/21 13:38:12 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -148,6 +148,10 @@ pg_write_history(char *s)
148148
{
149149
enumhistcontrolHC;
150150

151+
/* Flushing of empty buffer should do nothing */
152+
if (*s==0)
153+
return;
154+
151155
prev_hist=NULL;
152156

153157
HC=GetHistControlConfig();
@@ -295,13 +299,20 @@ initializeInput(int flags)
295299
}
296300

297301

302+
/* This function is designed for saving the readline history when user
303+
* run \s command or when psql finishes.
304+
* We have an argument named encodeFlag to handle those cases differently
305+
* In that case of call via \s we don't really need to encode \n as \x01,
306+
* but when we save history for Readline we must do that conversion
307+
*/
298308
bool
299-
saveHistory(char*fname)
309+
saveHistory(char*fname,boolencodeFlag)
300310
{
301311
#ifdefUSE_READLINE
302312
if (useHistory&&fname)
303313
{
304-
encode_history();
314+
if (encodeFlag)
315+
encode_history();
305316
if (write_history(fname)==0)
306317
return true;
307318

@@ -331,7 +342,7 @@ finishInput(int exitstatus, void *arg)
331342
if (hist_size >=0)
332343
stifle_history(hist_size);
333344

334-
saveHistory(psql_history);
345+
saveHistory(psql_history, true);
335346
free(psql_history);
336347
psql_history=NULL;
337348
}

‎src/bin/psql/input.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/input.h,v 1.26 2006/03/06 04:45:21 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/input.h,v 1.27 2006/03/21 13:38:12 momjian Exp $
77
*/
88
#ifndefINPUT_H
99
#defineINPUT_H
@@ -37,7 +37,7 @@ char *gets_interactive(const char *prompt);
3737
char*gets_fromFile(FILE*source);
3838

3939
voidinitializeInput(intflags);
40-
boolsaveHistory(char*fname);
40+
boolsaveHistory(char*fname,boolencodeFlag);
4141

4242
voidpg_append_history(char*s,PQExpBufferhistory_buf);
4343
voidpg_clear_history(PQExpBufferhistory_buf);

‎src/bin/psql/mainloop.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.73 2006/03/06 15:09:04 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.74 2006/03/21 13:38:12 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"mainloop.h"
@@ -112,7 +112,7 @@ MainLoop(FILE *source)
112112
slashCmdStatus=PSQL_CMD_UNKNOWN;
113113
prompt_status=PROMPT_READY;
114114
if (pset.cur_cmd_interactive)
115-
pg_clear_history(history_buf);
115+
pg_write_history(history_buf->data);
116116

117117
if (pset.cur_cmd_interactive)
118118
putc('\n',stdout);
@@ -321,7 +321,8 @@ MainLoop(FILE *source)
321321
break;
322322
}
323323

324-
if (pset.cur_cmd_interactive&&prompt_status!=PROMPT_CONTINUE)
324+
if ((pset.cur_cmd_interactive&&prompt_status==PROMPT_READY)||
325+
(GetVariableBool(pset.vars,"SINGLELINE")&&prompt_status==PROMPT_CONTINUE))
325326
{
326327
/*
327328
*Pass all the contents of history_buf to readline

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp