Re: psql misbehaves because of a simple typo - Mailing list pgsql-hackers
| From | Bruce Momjian |
|---|---|
| Subject | Re: psql misbehaves because of a simple typo |
| Date | |
| Msg-id | 200112281933.fBSJX0T05480@candle.pha.pa.us Whole thread Raw |
| In response to | Re: psql misbehaves because of a simple typo (Peter Eisentraut <peter_e@gmx.net>) |
| List | pgsql-hackers |
> Bruce Momjian writes:
>
> > 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.
>
> I don't think this works when the command is \g because you're testing for
> the cleared buffer too early. Look at what happens under "if
> (slashCmdStatus == CMD_SEND)". The test should be after that (around line
> 489 in original copy).
Are you sure?
test=> (select
test(> \g
ERROR: parser: parse error at or near ""
test(>
I now see the next \p kills me:
test(> \p
( select
test=>
Oops, line 489 doesn't work either:
test=> (select
test(> \g
ERROR: parser: parse error at or near ""
test=>
I now remember how confusing the previous_buffer handling is. It is
this line that is tricky:
/* handle backslash command */
slashCmdStatus = HandleSlashCmds(&line[i],
query_buf->len > 0 ? query_buf : previous_buf,
^^^^^^^^^^^^^^^^^^^^^^^^
&end_of_cmd);
It works now:
test=> (select
test(> \g
ERROR: parser: parse error at or near ""
test(> \p
(select
Patch attached.
--
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.45
diff -c -r1.45 mainloop.c
*** src/bin/psql/mainloop.c 2001/12/28 05:01:05 1.45
--- src/bin/psql/mainloop.c 2001/12/28 19:12:37
***************
*** 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 ----
***************
*** 473,479 ****
if ((slashCmdStatus == CMD_SEND || slashCmdStatus == CMD_NEWEDIT) &&
query_buf->len == 0)
{
! /* copy previous buffer to current for for handling */
appendPQExpBufferStr(query_buf, previous_buf->data);
}
--- 472,478 ----
if ((slashCmdStatus == CMD_SEND || slashCmdStatus == CMD_NEWEDIT) &&
query_buf->len == 0)
{
! /* copy previous buffer to current for handling */
appendPQExpBufferStr(query_buf, previous_buf->data);
}
***************
*** 486,491 ****
--- 485,493 ----
appendPQExpBufferStr(previous_buf, query_buf->data);
resetPQExpBuffer(query_buf);
}
+
+ if (query_buf->len == 0 && previous_buf->len == 0)
+ paren_level = 0;
/* process anything left after the backslash command */
i += end_of_cmd - &line[i];
pgsql-hackers by date: