forked from huawei/openGauss-server
check sql valid in for rec in query
Offering: openGaussDev More detail: check sql valid in for rec in query Match-id-ef6b3cb6dfe3e7c5f2abb1c0a04d603347d7da81
This commit is contained in:
parent
19589a89df
commit
58be337a09
|
|
@ -2963,6 +2963,10 @@ for_control : for_variable K_IN
|
||||||
check_assignable((PLpgSQL_datum *)newp->rec ?
|
check_assignable((PLpgSQL_datum *)newp->rec ?
|
||||||
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
||||||
} else {
|
} else {
|
||||||
|
/* check the sql */
|
||||||
|
if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
||||||
|
(void)getCursorTupleDesc(expr1, false, true);
|
||||||
|
}
|
||||||
newp->rec = $1.rec;
|
newp->rec = $1.rec;
|
||||||
check_assignable((PLpgSQL_datum *) newp->rec, @1);
|
check_assignable((PLpgSQL_datum *) newp->rec, @1);
|
||||||
}
|
}
|
||||||
|
|
@ -2979,6 +2983,10 @@ for_control : for_variable K_IN
|
||||||
check_assignable((PLpgSQL_datum *)newp->rec ?
|
check_assignable((PLpgSQL_datum *)newp->rec ?
|
||||||
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
||||||
} else {
|
} else {
|
||||||
|
/* check the sql */
|
||||||
|
if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
||||||
|
(void)getCursorTupleDesc(expr1, false, true);
|
||||||
|
}
|
||||||
newp->row = $1.row;
|
newp->row = $1.row;
|
||||||
check_assignable((PLpgSQL_datum *) newp->row, @1);
|
check_assignable((PLpgSQL_datum *) newp->row, @1);
|
||||||
}
|
}
|
||||||
|
|
@ -2995,6 +3003,10 @@ for_control : for_variable K_IN
|
||||||
check_assignable((PLpgSQL_datum *)newp->rec ?
|
check_assignable((PLpgSQL_datum *)newp->rec ?
|
||||||
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
(PLpgSQL_datum *)newp->rec : (PLpgSQL_datum *)newp->row, @1);
|
||||||
} else {
|
} else {
|
||||||
|
/* check the sql */
|
||||||
|
if (u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
||||||
|
(void)getCursorTupleDesc(expr1, false, true);
|
||||||
|
}
|
||||||
/* convert single scalar to list */
|
/* convert single scalar to list */
|
||||||
newp->row = make_scalar_list1($1.name, $1.scalar, $1.dno, $1.lineno, @1);
|
newp->row = make_scalar_list1($1.name, $1.scalar, $1.dno, $1.lineno, @1);
|
||||||
/* no need for check_assignable */
|
/* no need for check_assignable */
|
||||||
|
|
@ -4342,6 +4354,7 @@ stmt_open : K_OPEN cursor_variable
|
||||||
yyerror("syntax error");
|
yyerror("syntax error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef ENABLE_MULTIPLE_NODES
|
||||||
if (newp->query != NULL && u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
if (newp->query != NULL && u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
||||||
(void)getCursorTupleDesc(newp->query, false, true);
|
(void)getCursorTupleDesc(newp->query, false, true);
|
||||||
}
|
}
|
||||||
|
|
@ -4349,6 +4362,7 @@ stmt_open : K_OPEN cursor_variable
|
||||||
{
|
{
|
||||||
(void)getCursorTupleDesc(newp->dynquery, false, true);
|
(void)getCursorTupleDesc(newp->dynquery, false, true);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -8773,9 +8787,11 @@ make_execsql_stmt(int firsttoken, int location)
|
||||||
pfree_ext(ds.data);
|
pfree_ext(ds.data);
|
||||||
|
|
||||||
check_sql_expr(expr->query, location, 0);
|
check_sql_expr(expr->query, location, 0);
|
||||||
|
#ifndef ENABLE_MULTIPLE_NODES
|
||||||
if (firsttoken == K_SELECT && u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
if (firsttoken == K_SELECT && u_sess->attr.attr_sql.sql_compatibility == A_FORMAT && ALLOW_PROCEDURE_COMPILE_CHECK) {
|
||||||
(void)getCursorTupleDesc(expr, false, true);
|
(void)getCursorTupleDesc(expr, false, true);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
execsql = (PLpgSQL_stmt_execsql *)palloc(sizeof(PLpgSQL_stmt_execsql));
|
execsql = (PLpgSQL_stmt_execsql *)palloc(sizeof(PLpgSQL_stmt_execsql));
|
||||||
execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
|
execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
|
||||||
execsql->lineno = plpgsql_location_to_lineno(location);
|
execsql->lineno = plpgsql_location_to_lineno(location);
|
||||||
|
|
|
||||||
|
|
@ -2732,6 +2732,61 @@ NOTICE: drop cascades to function pkg_val_2.p1()
|
||||||
DROP PACKAGE pck2;
|
DROP PACKAGE pck2;
|
||||||
NOTICE: drop cascades to function pkg_val_2.p1()
|
NOTICE: drop cascades to function pkg_val_2.p1()
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
-- test check sql in for rec in query loop
|
||||||
|
create or replace function check_f04 return int as
|
||||||
|
declare
|
||||||
|
v_2 number(10,2):=-213.989;
|
||||||
|
v_3 float:=22.34;
|
||||||
|
v_4 char(1):='q';
|
||||||
|
v_6 date:='1999-09-09';
|
||||||
|
v_7 clob:='dddd';
|
||||||
|
v_8 blob:='ad';
|
||||||
|
begin
|
||||||
|
raise info '1-0 %', v_6;
|
||||||
|
for v_6 in select c3 from check_tab1 order by c3 limit 6
|
||||||
|
loop
|
||||||
|
raise info '1-1 %', v_6;
|
||||||
|
end loop;
|
||||||
|
raise info '1-2 %', v_6;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
exception
|
||||||
|
when others then
|
||||||
|
raise info 'error is %',sqlerrm;
|
||||||
|
return 0;
|
||||||
|
end;
|
||||||
|
/
|
||||||
|
ERROR: compile failed when parse the query: select c3 from check_tab1 order by c3 limit 6
|
||||||
|
DETAIL: relation "check_tab1" does not exist on datanode1
|
||||||
|
CONTEXT: compilation of PL/pgSQL function "check_f04" near line 11
|
||||||
|
create table check_tab1(a int);
|
||||||
|
create or replace function check_f04 return int as
|
||||||
|
declare
|
||||||
|
v_2 number(10,2):=-213.989;
|
||||||
|
v_3 float:=22.34;
|
||||||
|
v_4 char(1):='q';
|
||||||
|
v_6 date:='1999-09-09';
|
||||||
|
v_7 clob:='dddd';
|
||||||
|
v_8 blob:='ad';
|
||||||
|
begin
|
||||||
|
raise info '1-0 %', v_6;
|
||||||
|
for v_6 in select c3 from check_tab1 order by c3 limit 6
|
||||||
|
loop
|
||||||
|
raise info '1-1 %', v_6;
|
||||||
|
end loop;
|
||||||
|
raise info '1-2 %', v_6;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
exception
|
||||||
|
when others then
|
||||||
|
raise info 'error is %',sqlerrm;
|
||||||
|
return 0;
|
||||||
|
end;
|
||||||
|
/
|
||||||
|
ERROR: compile failed when parse the query: select c3 from check_tab1 order by c3 limit 6
|
||||||
|
DETAIL: column "c3" does not exist
|
||||||
|
CONTEXT: compilation of PL/pgSQL function "check_f04" near line 11
|
||||||
|
drop table check_tab1;
|
||||||
reset behavior_compat_options;
|
reset behavior_compat_options;
|
||||||
-- ref package cursor attr at first
|
-- ref package cursor attr at first
|
||||||
create table t1(a int, b int);
|
create table t1(a int, b int);
|
||||||
|
|
|
||||||
|
|
@ -2139,6 +2139,60 @@ end pck1;
|
||||||
DROP PACKAGE pck1;
|
DROP PACKAGE pck1;
|
||||||
DROP PACKAGE pck2;
|
DROP PACKAGE pck2;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
-- test check sql in for rec in query loop
|
||||||
|
create or replace function check_f04 return int as
|
||||||
|
declare
|
||||||
|
v_2 number(10,2):=-213.989;
|
||||||
|
v_3 float:=22.34;
|
||||||
|
v_4 char(1):='q';
|
||||||
|
v_6 date:='1999-09-09';
|
||||||
|
v_7 clob:='dddd';
|
||||||
|
v_8 blob:='ad';
|
||||||
|
begin
|
||||||
|
raise info '1-0 %', v_6;
|
||||||
|
for v_6 in select c3 from check_tab1 order by c3 limit 6
|
||||||
|
loop
|
||||||
|
raise info '1-1 %', v_6;
|
||||||
|
end loop;
|
||||||
|
raise info '1-2 %', v_6;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
exception
|
||||||
|
when others then
|
||||||
|
raise info 'error is %',sqlerrm;
|
||||||
|
return 0;
|
||||||
|
end;
|
||||||
|
/
|
||||||
|
|
||||||
|
create table check_tab1(a int);
|
||||||
|
|
||||||
|
create or replace function check_f04 return int as
|
||||||
|
declare
|
||||||
|
v_2 number(10,2):=-213.989;
|
||||||
|
v_3 float:=22.34;
|
||||||
|
v_4 char(1):='q';
|
||||||
|
v_6 date:='1999-09-09';
|
||||||
|
v_7 clob:='dddd';
|
||||||
|
v_8 blob:='ad';
|
||||||
|
begin
|
||||||
|
raise info '1-0 %', v_6;
|
||||||
|
for v_6 in select c3 from check_tab1 order by c3 limit 6
|
||||||
|
loop
|
||||||
|
raise info '1-1 %', v_6;
|
||||||
|
end loop;
|
||||||
|
raise info '1-2 %', v_6;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
exception
|
||||||
|
when others then
|
||||||
|
raise info 'error is %',sqlerrm;
|
||||||
|
return 0;
|
||||||
|
end;
|
||||||
|
/
|
||||||
|
|
||||||
|
drop table check_tab1;
|
||||||
|
|
||||||
reset behavior_compat_options;
|
reset behavior_compat_options;
|
||||||
|
|
||||||
-- ref package cursor attr at first
|
-- ref package cursor attr at first
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue