Tom Lane writes:
> In current sources:
>
> regression=# create table tt1 (i2 int2, i4 int4, f8 float8,
> regression(# \r
> Query buffer reset (cleared).
> regression(# select 2;
> regression(# -- nothing happens because psql still wants a right paren
>
> Not sure if there is any other state that needs to be reset along
> with the paren counter.
I can't think of any.
Here's an attempt at a patch. It seems to work, but I haven't thought
about it a whole lot.
Index: command.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/command.c,v
retrieving revision 1.69
diff -u -r1.69 command.c
--- command.c 7 Mar 2002 17:54:39 -0000 1.69
+++ command.c 17 Mar 2002 21:48:59 -0000
@@ -52,7 +52,8 @@
static backslashResult exec_command(const char *cmd,
const char *options_string,
const char **continue_parse,
- PQExpBuffer query_buf);
+ PQExpBuffer query_buf,
+ volatile int *paren_level);
/* different ways for scan_option to handle parameter words */
enum option_type
@@ -94,7 +95,8 @@
backslashResult
HandleSlashCmds(const char *line,
PQExpBuffer query_buf,
- const char **end_of_cmd)
+ const char **end_of_cmd,
+ volatile int *paren_level)
{
backslashResult status = CMD_SKIP_LINE;
char *my_line;
@@ -132,7 +134,7 @@
my_line[blank_loc] = '\0';
}
- status = exec_command(my_line, options_string, &continue_parse, query_buf);
+ status = exec_command(my_line, options_string, &continue_parse, query_buf, paren_level);
if (status == CMD_UNKNOWN)
{
@@ -147,7 +149,7 @@
new_cmd[1] = '\0';
/* use line for options, because my_line was clobbered above */
- status = exec_command(new_cmd, line + 1, &continue_parse, query_buf);
+ status = exec_command(new_cmd, line + 1, &continue_parse, query_buf, paren_level);
/*
* continue_parse must be relative to my_line for calculation
@@ -192,7 +194,8 @@
exec_command(const char *cmd,
const char *options_string,
const char **continue_parse,
- PQExpBuffer query_buf)
+ PQExpBuffer query_buf,
+ volatile int *paren_level)
{
bool success = true; /* indicate here if the command ran ok or
* failed */
@@ -632,6 +635,8 @@
else if (strcmp(cmd, "r") == 0 || strcmp(cmd, "reset") == 0)
{
resetPQExpBuffer(query_buf);
+ if (paren_level)
+ *paren_level = 0;
if (!quiet)
puts(gettext("Query buffer reset (cleared)."));
}
Index: command.h
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/command.h,v
retrieving revision 1.13
diff -u -r1.13 command.h
--- command.h 5 Nov 2001 17:46:30 -0000 1.13
+++ command.h 17 Mar 2002 21:48:59 -0000
@@ -28,7 +28,8 @@
backslashResult HandleSlashCmds(const char *line,
PQExpBuffer query_buf,
- const char **end_of_cmd);
+ const char **end_of_cmd,
+ volatile int *paren_level);
int
process_file(char *filename);
Index: mainloop.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.46
diff -u -r1.46 mainloop.c
--- mainloop.c 18 Feb 2002 05:57:41 -0000 1.46
+++ mainloop.c 17 Mar 2002 21:49:00 -0000
@@ -465,7 +465,8 @@
/* handle backslash command */
slashCmdStatus = HandleSlashCmds(&line[i],
query_buf->len > 0 ? query_buf : previous_buf,
- &end_of_cmd);
+ &end_of_cmd,
+ &paren_level);
success = slashCmdStatus != CMD_ERROR;
Index: startup.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/startup.c,v
retrieving revision 1.54
diff -u -r1.54 startup.c
--- startup.c 5 Nov 2001 17:46:31 -0000 1.54
+++ startup.c 17 Mar 2002 21:49:01 -0000
@@ -256,7 +256,7 @@
if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
puts(options.action_string);
- successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR
+ successResult = HandleSlashCmds(options.action_string, NULL, NULL, NULL) != CMD_ERROR
? EXIT_SUCCESS : EXIT_FAILURE;
}
--
Peter Eisentraut peter_e@gmx.net