Fix of several issues:

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 ;( 

Regards,
        Sergey

*****************************************************
Sergey E. Koposov
Max Planck Institute for Astronomy
Web: http://lnfm1.sai.msu.ru/~math 
E-mail: [EMAIL PROTECTED]



Index: command.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/command.c,v
retrieving revision 1.163
diff -c -r1.163 command.c
*** command.c   4 Mar 2006 04:30:40 -0000       1.163
--- command.c   5 Mar 2006 03:42:13 -0000
***************
*** 753,759 ****
  
                expand_tilde(&fname);
                /* This scrolls off the screen when using /dev/tty */
!               success = saveHistory(fname ? fname : DEVTTY);
                if (success && !quiet && fname)
                        printf(gettext("Wrote history to file \"%s/%s\".\n"),
                                   pset.dirname ? pset.dirname : ".", fname);
--- 753,759 ----
  
                expand_tilde(&fname);
                /* This scrolls off the screen when using /dev/tty */
!               success = saveHistory(fname ? fname : DEVTTY, false);
                if (success && !quiet && fname)
                        printf(gettext("Wrote history to file \"%s/%s\".\n"),
                                   pset.dirname ? pset.dirname : ".", fname);
Index: input.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/input.c,v
retrieving revision 1.50
diff -c -r1.50 input.c
*** input.c     13 Feb 2006 17:09:25 -0000      1.50
--- input.c     5 Mar 2006 03:42:13 -0000
***************
*** 148,153 ****
--- 148,158 ----
                enum histcontrol HC;
                
                s = history_buf->data;
+               
+               /* Flushing of empty buffer should do nothing */
+               if  (*s == 0)
+                       return;
+               
                prev_hist = NULL;
                        
                HC = GetHistControlConfig();
***************
*** 297,309 ****
  }
  
  
  bool
! saveHistory(char *fname)
  {
  #ifdef USE_READLINE
        if (useHistory && fname)
        {
!               encode_history();               
                if (write_history(fname) == 0)
                        return true;
  
--- 302,321 ----
  }
  
  
+ /* 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, bool encodeFlag)
  {
  #ifdef USE_READLINE
        if (useHistory && fname)
        {
!               if (encodeFlag)
!                       encode_history();
                if (write_history(fname) == 0)
                        return true;
  
***************
*** 333,339 ****
                if (hist_size >= 0)
                        stifle_history(hist_size);
  
!               saveHistory(psql_history);
                free(psql_history);
                psql_history = NULL;
        }
--- 345,351 ----
                if (hist_size >= 0)
                        stifle_history(hist_size);
  
!               saveHistory(psql_history, true);
                free(psql_history);
                psql_history = NULL;
        }
Index: input.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/input.h,v
retrieving revision 1.24
diff -c -r1.24 input.h
*** input.h     11 Feb 2006 21:55:35 -0000      1.24
--- input.h     5 Mar 2006 03:42:13 -0000
***************
*** 37,43 ****
  char     *gets_fromFile(FILE *source);
  
  void          initializeInput(int flags);
! bool          saveHistory(char *fname);
  
  void pgadd_history(char *s, PQExpBuffer history_buf);
  void pgclear_history(PQExpBuffer history_buf);
--- 37,43 ----
  char     *gets_fromFile(FILE *source);
  
  void          initializeInput(int flags);
! bool          saveHistory(char *fname, bool encodeFlag);
  
  void pgadd_history(char *s, PQExpBuffer history_buf);
  void pgclear_history(PQExpBuffer history_buf);
Index: mainloop.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.70
diff -c -r1.70 mainloop.c
*** mainloop.c  11 Feb 2006 21:55:35 -0000      1.70
--- mainloop.c  5 Mar 2006 03:42:14 -0000
***************
*** 110,116 ****
                        slashCmdStatus = PSQL_CMD_UNKNOWN;
                        prompt_status = PROMPT_READY;
                        if (pset.cur_cmd_interactive)
!                               pgclear_history(history_buf);                   
  
                        if (pset.cur_cmd_interactive)
                                putc('\n', stdout);
--- 110,116 ----
                        slashCmdStatus = PSQL_CMD_UNKNOWN;
                        prompt_status = PROMPT_READY;
                        if (pset.cur_cmd_interactive)
!                               pgflush_history(history_buf);                   
  
                        if (pset.cur_cmd_interactive)
                                putc('\n', stdout);
***************
*** 301,307 ****
                                break;
                }
                
!               if (pset.cur_cmd_interactive && prompt_status != 
PROMPT_CONTINUE)
                        /*
                         *      Pass all the contents of history_buf to readline
                         *      and free the history buffer.
--- 301,308 ----
                                break;
                }
                
!               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
                         *      and free the history buffer.
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to