Hello,

I'm sending the patch fixing the \r bug:

On Wed, 31 May 2006, Tom Lane wrote:

The example that seriously sucks is:

regression=# select foo ...
regression-# \r
Query buffer reset (cleared).
now control-P brings back:
regression=# select foo ...
\r

In my fix the currently-written query is completely erased if \r is
invoked. I think that's the most logic behavior.
So, the example of work:

wsdb=# select 1;
 ?column?
----------
        1
(1 row)

wsdb=# select
wsdb-# \r
Query buffer reset (cleared).
wsdb=#
Control-P now brings back:
wsdb=# \r

Another Control-P brings back:
wsdb=# select 1;


Also, \e is seriously broken: after you edit the text and exit the
editor, the text is not reloaded into the visible display (although it
does seem to still be "behind the scenes" somewhere).

For that part, I currently do not see the possible fix, and I don't even think that it should be fixed, because there with current multi-line implementation there is no need for that.

For example, when we do
wsdb=# select 1+
wsdb-#
And press Control-P , the string "select 1+" is not in the history, and there is no need for that.

And in the case of \e editing, if in the external editor we have typed the incomplete query like "select 1+", the situation will be exactly the same and for the same reason...

So, I don't think, that this require fixing. In principal, probably it is possible to fix that in a different way: Suppose we executed the \e command and in the external editor we typed "select 1 +". And after the exit from the editor, psql produce wsdb=# select 1 + (and put cursor in the end of the line).

That can be reasonable (I'm not sure that it's possible to do that with readline, but should be). But I would consider that as a new feature (probably not very useful), not as a bug fix.

Regards,
        Sergey

*******************************************************************
Sergey E. Koposov
Max Planck Institute for Astronomy/Sternberg Astronomical Institute
Tel: +49-6221-528-349      Web: http://lnfm1.sai.msu.ru/~math
E-mail: [EMAIL PROTECTED]
Index: src/bin/psql/command.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/command.c,v
retrieving revision 1.168
diff -c -r1.168 command.c
*** src/bin/psql/command.c      1 Jun 2006 00:15:36 -0000       1.168
--- src/bin/psql/command.c      4 Jun 2006 03:57:48 -0000
***************
*** 729,734 ****
--- 729,735 ----
                psql_scan_reset(scan_state);
                if (!quiet)
                        puts(_("Query buffer reset (cleared)."));
+               status = PSQL_CMD_RESET_BUFFER;
        }
  
        /* \s save history in a file or show it on the screen */
Index: src/bin/psql/command.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/command.h,v
retrieving revision 1.25
diff -c -r1.25 command.h
*** src/bin/psql/command.h      5 Mar 2006 15:58:51 -0000       1.25
--- src/bin/psql/command.h      4 Jun 2006 03:57:48 -0000
***************
*** 18,23 ****
--- 18,24 ----
        PSQL_CMD_UNKNOWN = 0,                   /* not done parsing yet 
(internal only) */
        PSQL_CMD_SEND,                                  /* query complete; send 
off */
        PSQL_CMD_SKIP_LINE,                             /* keep building query 
*/
+       PSQL_CMD_RESET_BUFFER,                  /* reset the query buffer */
        PSQL_CMD_TERMINATE,                             /* quit program */
        PSQL_CMD_NEWEDIT,                               /* query buffer was 
changed (e.g., via \e) */
        PSQL_CMD_ERROR                                  /* the execution of the 
backslash command
Index: src/bin/psql/mainloop.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.74
diff -c -r1.74 mainloop.c
*** src/bin/psql/mainloop.c     21 Mar 2006 13:38:12 -0000      1.74
--- src/bin/psql/mainloop.c     4 Jun 2006 03:57:49 -0000
***************
*** 305,310 ****
--- 305,317 ----
                         */
                        if (first_query_scan && pset.cur_cmd_interactive)
                        {
+                               /* If the \r command have been sent we 
completely erase 
+                                * the previous (multiline command).
+                                * It won't be in the history after that 
+                                */
+                               if (slashCmdStatus == PSQL_CMD_RESET_BUFFER)
+                                       pg_clear_history(history_buf);
+                               
                                /* Sending a command (PSQL_CMD_SEND) zeros the 
length */
                                if (scan_result == PSCAN_BACKSLASH && 
query_buf->len != 0)
                                        pg_write_history(line);
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to