> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > OK, so what do we want to do? Clearing the buffer on a any backslash
> > command is clearly not what we want to do. Should we clear the buffer
> > on a backslash command _only_ if the number of paren's is not even? If
> > we don't clear the counter on a backslash command with uneven parens, do
> > we risk trapping people in psql?
>
> "Trap"? AFAIK \q works in any case.
>
> \r should reset both the buffer and the counter, and seems to do so,
> though I'm not quite seeing where it manages to accomplish the latter
> (command.c only resets query_buf). \e should probably provoke a
> recomputation of paren_level after the edit occurs. Offhand I do not
> think that any other backslash commands should reset either the buffer
> or the counter. Peter, your thoughts?
OK, here is a patch for 7.3. It clears the paren counter only when the
buffer is cleared. Forget what I said about recomputing quotes. You
can't use backslash commands while you are in quotes.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: src/bin/psql/mainloop.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.43
diff -c -r1.43 mainloop.c
*** src/bin/psql/mainloop.c 2001/11/05 17:46:31 1.43
--- src/bin/psql/mainloop.c 2001/12/28 04:41:48
***************
*** 447,453 ****
{
const char *end_of_cmd = NULL;
- paren_level = 0;
line[i - prevlen] = '\0'; /* overwrites backslash */
/* is there anything else on the line for the command? */
--- 447,452 ----
***************
*** 469,474 ****
--- 468,476 ----
&end_of_cmd);
success = slashCmdStatus != CMD_ERROR;
+
+ if (query_buf->len == 0)
+ paren_level = 0;
if ((slashCmdStatus == CMD_SEND || slashCmdStatus == CMD_NEWEDIT) &&
query_buf->len == 0)