From: Tom Lane Date: Tue, 21 May 2002 18:50:18 +0000 (+0000) Subject: Repair OPEN cursor(args), which I broke on 11/29/01 with a change to X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=37a858ab8ddacd3e9dff4d5ebb8505dcc5f5c569;p=users%2Fbernd%2Fpostgres.git Repair OPEN cursor(args), which I broke on 11/29/01 with a change to be smarter about parentheses in read_sql_construct(). Sigh. --- diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y index 98bf34345e..cde0af933f 100644 --- a/src/pl/plpgsql/src/gram.y +++ b/src/pl/plpgsql/src/gram.y @@ -1346,17 +1346,44 @@ stmt_open : K_OPEN lno cursor_varptr if (tok != '(') { plpgsql_error_lineno = yylineno; - elog(ERROR, "cursor %s has arguments", $3->refname); + elog(ERROR, "cursor %s has arguments", + $3->refname); } + /* + * Push back the '(', else read_sql_stmt + * will complain about unbalanced parens. + */ + plpgsql_push_back_token(tok); + new->argquery = read_sql_stmt("SELECT "); - /* Remove the trailing right paren, - * because we want "select 1, 2", not - * "select (1, 2)". + + /* + * Now remove the leading and trailing parens, + * because we want "select 1, 2", not + * "select (1, 2)". */ cp = new->argquery->query; - cp += strlen(cp); - --cp; + + if (strncmp(cp, "SELECT", 6) != 0) + { + plpgsql_error_lineno = yylineno; + elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", + new->argquery->query); + } + cp += 6; + while (*cp == ' ') /* could be more than 1 space here */ + cp++; + if (*cp != '(') + { + plpgsql_error_lineno = yylineno; + elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", + new->argquery->query); + } + *cp = ' '; + + cp += strlen(cp) - 1; + if (*cp != ')') { plpgsql_error_lineno = yylineno;