From 16e2af074e425278d8e8947d683b8ab8015928be Mon Sep 17 00:00:00 2001 From: wangfeihuo Date: Fri, 23 Aug 2024 11:26:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=A0=87=E9=A2=98=E3=80=91=EF=BC=9A?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E6=B8=B8=E6=A0=87=E5=90=8D=EF=BC=8C=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97=E5=B8=A6=E5=8D=95=E5=BC=95=E5=8F=B7=E3=80=81?= =?UTF-8?q?=E5=8F=8D=E5=BC=95=E5=8F=B7=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E5=86=85=E5=AE=B9=E3=80=91:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E6=B8=B8=E6=A0=87=E5=90=8D=EF=BC=8C=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97=E5=B8=A6=E5=8D=95=E5=BC=95=E5=8F=B7=E3=80=81?= =?UTF-8?q?=E5=8F=8D=E5=BC=95=E5=8F=B7=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98.=20?= =?UTF-8?q?=E3=80=90=E6=A0=B9=E5=9B=A0=E5=88=86=E6=9E=90=E3=80=91:=20?= =?UTF-8?q?=E5=9C=A8=E5=A4=84=E7=90=86cursor=20expression=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=A2=84=E8=AF=BB=E4=B8=A4=E4=BD=8D=E5=AF=BC=E8=87=B4?= =?UTF-8?q?yyextra->scanbuf=E7=9A=84=E5=86=85=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=20=E3=80=90=E5=AE=9E=E7=8E=B0=E6=96=B9=E6=A1=88=E3=80=91:=20?= =?UTF-8?q?=E9=A2=84=E8=AF=BB=E4=B8=A4=E4=BD=8D=E6=94=B9=E6=88=90=E5=85=88?= =?UTF-8?q?=E9=A2=84=E8=AF=BB=E4=B8=80=E4=BD=8D=EF=BC=8C=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=EF=BC=88=E5=86=8D=E9=A2=84=E8=AF=BB=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=BD=8D=E3=80=82=20=E3=80=90=E5=85=B3=E8=81=94=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E6=88=96issue=E3=80=91:=20https://e.gitee.com/opengau?= =?UTF-8?q?ssorg/dashboard=3Fissue=3DIAIJ67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/parser.cpp | 55 +++++++++++-------- .../regress/expected/cursor_expression.out | 13 +++++ src/test/regress/sql/cursor_expression.sql | 8 +++ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/common/backend/parser/parser.cpp b/src/common/backend/parser/parser.cpp index e4fe525536..f35542d0b0 100644 --- a/src/common/backend/parser/parser.cpp +++ b/src/common/backend/parser/parser.cpp @@ -741,30 +741,37 @@ int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner) break; } break; - case CURSOR: - GET_NEXT_TOKEN(); - core_yystype_1 = cur_yylval; // the value of cursor - cur_yylloc_1 = cur_yylloc; // the lloc of cursor - next_token_1 = next_token; // the token after curosr - GET_NEXT_TOKEN(); - core_yystype_2 = cur_yylval; // the value after cursor - cur_yylloc_2 = cur_yylloc; // the lloc after cursor - next_token_2 = next_token; // the token after after curosr - - if (next_token_1 == '(' && (is_select_stmt_definitely(next_token))) { - PARSE_CURSOR_PARENTHESES_AS_EXPR(); - } else if (is_prefer_parse_cursor_parentheses_as_expr() && !is_cursor_function_exist()) { - PARSE_CURSOR_PARENTHESES_AS_EXPR(); - } else { - PARSE_CURSOR_PARENTHESES_AS_FUNCTION(); - } - - if (t_thrd.proc->workingVersionNum < CURSOR_EXPRESSION_VERSION_NUMBER && - cur_token == CURSOR_EXPR) { - ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("Unsupported feature: cursor expression during the upgrade"))); - } - break; + case CURSOR: + GET_NEXT_TOKEN(); + core_yystype_1 = cur_yylval; // the value of cursor + cur_yylloc_1 = cur_yylloc; // the lloc of cursor + next_token_1 = next_token; // the token after curosr + if (next_token_1 != '(') { + /* save the lookahead token for next time */ + SET_LOOKAHEAD_TOKEN(); + /* and back up the output info to cur_token */ + lvalp->core_yystype = cur_yylval; + *llocp = cur_yylloc; + } else { + GET_NEXT_TOKEN(); + core_yystype_2 = cur_yylval; // the value after cursor + cur_yylloc_2 = cur_yylloc; // the lloc after cursor + next_token_2 = next_token; // the token after after curosr + + if (next_token_1 == '(' && (is_select_stmt_definitely(next_token))) { + PARSE_CURSOR_PARENTHESES_AS_EXPR(); + } else if (is_prefer_parse_cursor_parentheses_as_expr() && !is_cursor_function_exist()) { + PARSE_CURSOR_PARENTHESES_AS_EXPR(); + } else { + PARSE_CURSOR_PARENTHESES_AS_FUNCTION(); + } + if (t_thrd.proc->workingVersionNum < CURSOR_EXPRESSION_VERSION_NUMBER && + cur_token == CURSOR_EXPR) { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("Unsupported feature: cursor expression during the upgrade"))); + } + } + break; default: break; } diff --git a/src/test/regress/expected/cursor_expression.out b/src/test/regress/expected/cursor_expression.out index fe470f5703..1e7b0a4d18 100644 --- a/src/test/regress/expected/cursor_expression.out +++ b/src/test/regress/expected/cursor_expression.out @@ -938,7 +938,20 @@ NOTICE: CONTEXT: PL/pgSQL function inline_code_block line 10 at FETCH NOTICE: employee_name : zhangsan set enable_auto_explain = off; +create table abort_test(cid int,fid int); +-- expect error +start transaction; +cursor 'abort' for select * from abort_test order by 1; +ERROR: syntax error at or near "'abort'" +LINE 1: cursor 'abort' for select * from abort_test order by 1; + ^ +close 'abort'; +ERROR: syntax error at or near "'abort'" +LINE 1: close 'abort'; + ^ +commit; -- clean +drop table abort_test; drop table test_insert; drop procedure pro_cursor_0011_02; drop table t_cursor_0011_01; diff --git a/src/test/regress/sql/cursor_expression.sql b/src/test/regress/sql/cursor_expression.sql index 435c59fb3b..ac563df18b 100644 --- a/src/test/regress/sql/cursor_expression.sql +++ b/src/test/regress/sql/cursor_expression.sql @@ -550,7 +550,15 @@ END; / set enable_auto_explain = off; +create table abort_test(cid int,fid int); +-- expect error +start transaction; +cursor 'abort' for select * from abort_test order by 1; +close 'abort'; +commit; + -- clean +drop table abort_test; drop table test_insert; drop procedure pro_cursor_0011_02; drop table t_cursor_0011_01; -- Gitee