diff options
author | Bruce Momjian | 2006-03-21 13:38:12 +0000 |
---|---|---|
committer | Bruce Momjian | 2006-03-21 13:38:12 +0000 |
commit | db6395f5fa64d2db740d28497b042c1127ffbc96 (patch) | |
tree | aa6bebaf857c6b165f512fa94198884a38dc159c | |
parent | 8affb610d5f0cd9e0ac642c45f46d4112de90269 (diff) |
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 was
almost
> broken ;(
Sergey E. Koposov
-rw-r--r-- | src/bin/psql/command.c | 2 | ||||
-rw-r--r-- | src/bin/psql/input.c | 17 | ||||
-rw-r--r-- | src/bin/psql/input.h | 2 | ||||
-rw-r--r-- | src/bin/psql/mainloop.c | 5 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 44eadc718a..c80c2d5974 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -753,7 +753,7 @@ exec_command(const char *cmd, expand_tilde(&fname); /* This scrolls off the screen when using /dev/tty */ - success = saveHistory(fname ? fname : DEVTTY); + success = saveHistory(fname ? fname : DEVTTY, false); if (success && !quiet && fname) printf(gettext("Wrote history to file \"%s/%s\".\n"), pset.dirname ? pset.dirname : ".", fname); diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index e5360e8895..ece56158c9 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -148,6 +148,10 @@ pg_write_history(char *s) { enum histcontrol HC; + /* Flushing of empty buffer should do nothing */ + if (*s == 0) + return; + prev_hist = NULL; HC = GetHistControlConfig(); @@ -295,13 +299,20 @@ initializeInput(int flags) } +/* This function is designed for saving the readline history when user + * run \s command or when psql finishes. + * We have an argument named encodeFlag to handle those cases differently + * In that case of call via \s we don't really need to encode \n as \x01, + * but when we save history for Readline we must do that conversion + */ bool -saveHistory(char *fname) +saveHistory(char *fname, bool encodeFlag) { #ifdef USE_READLINE if (useHistory && fname) { - encode_history(); + if (encodeFlag) + encode_history(); if (write_history(fname) == 0) return true; @@ -331,7 +342,7 @@ finishInput(int exitstatus, void *arg) if (hist_size >= 0) stifle_history(hist_size); - saveHistory(psql_history); + saveHistory(psql_history, true); free(psql_history); psql_history = NULL; } diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h index 77d0e8f9d4..5bb7232231 100644 --- a/src/bin/psql/input.h +++ b/src/bin/psql/input.h @@ -37,7 +37,7 @@ char *gets_interactive(const char *prompt); char *gets_fromFile(FILE *source); void initializeInput(int flags); -bool saveHistory(char *fname); +bool saveHistory(char *fname, bool encodeFlag); void pg_append_history(char *s, PQExpBuffer history_buf); void pg_clear_history(PQExpBuffer history_buf); diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index 386ec28858..c345464d79 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -112,7 +112,7 @@ MainLoop(FILE *source) slashCmdStatus = PSQL_CMD_UNKNOWN; prompt_status = PROMPT_READY; if (pset.cur_cmd_interactive) - pg_clear_history(history_buf); + pg_write_history(history_buf->data); if (pset.cur_cmd_interactive) putc('\n', stdout); @@ -321,7 +321,8 @@ MainLoop(FILE *source) break; } - if (pset.cur_cmd_interactive && prompt_status != PROMPT_CONTINUE) + if ((pset.cur_cmd_interactive && prompt_status == PROMPT_READY) || + (GetVariableBool(pset.vars, "SINGLELINE") && prompt_status == PROMPT_CONTINUE)) { /* * Pass all the contents of history_buf to readline |