【标题】:修复使用关键字作为游标名,关键字带单引号、反引号报错信息不合理的问题

【实现内容】: 修复使用关键字作为游标名,关键字带单引号、反引号报错信息不合理的问题.
【根因分析】: 在处理cursor expression时,预读两位导致yyextra->scanbuf的内容变更
【实现方案】: 预读两位改成先预读一位,判断是(再预读下一位。
【关联需求或issue】: https://e.gitee.com/opengaussorg/dashboard?issue=IAIJ67
This commit is contained in:
wangfeihuo
2024-08-23 11:26:33 +08:00
parent 4b934c709e
commit 16e2af074e
3 changed files with 51 additions and 23 deletions

View File

@ -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
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;
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;
}

View File

@ -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;

View File

@ -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;