mysql fetch into exit

This commit is contained in:
nnuanyang
2023-04-10 23:11:36 -07:00
parent a38a82270c
commit 83b5653167
5 changed files with 79 additions and 4 deletions

View File

@ -345,7 +345,8 @@ static const struct b_format_behavior_compat_entry b_format_behavior_compat_opti
{"set_session_transaction", B_FORMAT_OPT_ENABLE_SET_SESSION_TRANSACTION},
{"enable_set_variables", B_FORMAT_OPT_ENABLE_SET_VARIABLES},
{"enable_modify_column", B_FORMAT_OPT_ENABLE_MODIFY_COLUMN},
{"default_collation", B_FORMAT_OPT_DEFAULT_COLLATION}
{"default_collation", B_FORMAT_OPT_DEFAULT_COLLATION},
{"fetch", B_FORMAT_OPT_FETCH}
};
typedef struct behavior_compat_entry {
@ -3334,7 +3335,8 @@ static bool b_format_forbid_distribute_parameter(const char *elem)
const char *forbidList[] = {
"set_session_transaction",
"enable_set_variables",
"enable_modify_column"
"enable_modify_column",
"fetch"
};
for (int i = 0; i < B_FORMAT_FORBID_GUC_NUM; i++) {
if (strcmp(forbidList[i], elem) == 0) {

View File

@ -7531,6 +7531,10 @@ static int exec_stmt_fetch(PLpgSQL_execstate* estate, PLpgSQL_stmt_fetch* stmt)
exec_set_found(estate, n != 0);
exec_set_cursor_found(estate, (n != 0) ? PLPGSQL_TRUE : PLPGSQL_FALSE, stmt->curvar + CURSOR_FOUND);
exec_set_notfound(estate, (n == 0) ? PLPGSQL_TRUE : PLPGSQL_FALSE, stmt->curvar + CURSOR_NOTFOUND);
if (B_FETCH && n == 0) {
return PLPGSQL_RC_EXIT;
}
exec_set_rowcount(estate, n, false, stmt->curvar + CURSOR_ROWCOUNT);
return PLPGSQL_RC_OK;

View File

@ -140,7 +140,8 @@ extern bool contain_backend_version(uint32 version_number);
#define B_FORMAT_OPT_ENABLE_SET_VARIABLES 2
#define B_FORMAT_OPT_ENABLE_MODIFY_COLUMN 4
#define B_FORMAT_OPT_DEFAULT_COLLATION 8
#define B_FORMAT_OPT_MAX 4
#define B_FORMAT_OPT_FETCH 16
#define B_FORMAT_OPT_MAX 5
#define ENABLE_SET_SESSION_TRANSACTION \
((u_sess->utils_cxt.b_format_behavior_compat_flags & B_FORMAT_OPT_ENABLE_SET_SESSION_TRANSACTION) && \
@ -151,6 +152,8 @@ extern bool contain_backend_version(uint32 version_number);
#define ENABLE_MODIFY_COLUMN \
((u_sess->utils_cxt.b_format_behavior_compat_flags & B_FORMAT_OPT_ENABLE_MODIFY_COLUMN) && \
u_sess->attr.attr_sql.sql_compatibility == B_FORMAT)
#define B_FETCH ((u_sess->utils_cxt.b_format_behavior_compat_flags & B_FORMAT_OPT_FETCH) && \
u_sess->attr.attr_sql.sql_compatibility == B_FORMAT)
#define OPT_DISPLAY_LEADING_ZERO 1
#define OPT_END_MONTH_CALCULATE 2
@ -218,7 +221,7 @@ extern bool contain_backend_version(uint32 version_number);
#define PLSQL_COMPILE_FOR_LOOP (u_sess->utils_cxt.plsql_compile_behavior_compat_flags & PLPSQL_OPT_FOR_LOOP)
#define PLSQL_COMPILE_OUTPARAM (u_sess->utils_cxt.plsql_compile_behavior_compat_flags & PLPSQL_OPT_OUTPARAM)
#define SELECT_INTO_RETURN_NULL (u_sess->utils_cxt.behavior_compat_flags & OPT_SELECT_INTO_RETURN_NULL)
/* define database compatibility Attribute */

View File

@ -296,6 +296,46 @@ begin
close c1_all;
end if;
end
-- mysql fetch 自动退出
show b_format_behavior_compat_options;
b_format_behavior_compat_options
----------------------------------
(1 row)
set b_format_behavior_compat_options = 'fetch';
create or replace procedure test_cursor_1
as
company_name varchar(100);
company_loc varchar(100);
company_no integer;
begin
declare c1_all cursor is --cursor without args
select name, loc, no from company order by 1, 2, 3;
if not c1_all%isopen then
open c1_all;
end if;
loop
fetch c1_all into company_name, company_loc, company_no;
raise notice '% : % : %',company_name,company_loc,company_no;
end loop;
if c1_all%isopen then
close c1_all;
end if;
end;
/
call test_cursor_1();
NOTICE: backberry : canada : 3
NOTICE: macrosoft : usa : 1
NOTICE: oracle : usa : 2
test_cursor_1
---------------
(1 row)
set b_fetch = off;
ERROR: unrecognized configuration parameter "b_fetch"
-- test declare condition
create or replace procedure test_condition_1 as
declare

View File

@ -241,6 +241,32 @@ begin
end if;
end;
/
-- mysql fetch 自动退出
show b_format_behavior_compat_options;
set b_format_behavior_compat_options = 'fetch';
create or replace procedure test_cursor_1
as
company_name varchar(100);
company_loc varchar(100);
company_no integer;
begin
declare c1_all cursor is --cursor without args
select name, loc, no from company order by 1, 2, 3;
if not c1_all%isopen then
open c1_all;
end if;
loop
fetch c1_all into company_name, company_loc, company_no;
raise notice '% : % : %',company_name,company_loc,company_no;
end loop;
if c1_all%isopen then
close c1_all;
end if;
end;
/
call test_cursor_1();
set b_fetch = off;
-- test declare condition
create or replace procedure test_condition_1 as
declare