[CP] [to #2024110600104979133] fix: adjust solution to return null value to driver for closed cursor

This commit is contained in:
haohao022 2024-12-13 15:18:04 +00:00 committed by ob-robot
parent 37f0dedd11
commit d42b0c27f0
2 changed files with 23 additions and 19 deletions

View File

@ -1598,6 +1598,27 @@ int ObPL::execute(ObExecContext &ctx,
ObUserDefinedType::destruct_objparam(pl_sym_allocator,
pl.get_params().at(i),
ctx.get_my_session());
} else if (pl.is_top_call()
&& pl.get_params().at(i).get_meta().get_extend_type() == PL_REF_CURSOR_TYPE) {
ObObjParam &cursor_param = pl.get_params().at(i);
const ObPLCursorInfo *cursor = reinterpret_cast<ObPLCursorInfo *>(cursor_param.get_ext());
OX (params->at(i) = cursor_param);
if (OB_NOT_NULL(cursor)) {
uint64_t compat_version = 0;
bool null_value_for_closed_cursor = false;
CK (OB_NOT_NULL(ctx.get_my_session()));
OZ (ctx.get_my_session()->get_compatibility_version(compat_version));
OZ (ObCompatControl::check_feature_enable(compat_version,
ObCompatFeatureType::NULL_VALUE_FOR_CLOSED_CURSOR,
null_value_for_closed_cursor));
if (null_value_for_closed_cursor && cursor->is_session_cursor() && !cursor->isopen()) {
OZ (ObSPIService::spi_add_ref_cursor_refcount(&pl.get_exec_ctx(), &cursor_param, -1));
OX (params->at(i).set_obj_value(static_cast<uint64_t>(0))); // return closed refcursor as null
if (0 == cursor->get_ref_count()) {
OZ (ctx.get_my_session()->close_cursor(cursor->get_id()));
}
}
}
} else {
OX (params->at(i) = pl.get_params().at(i));
}

View File

@ -4170,8 +4170,6 @@ int ObSPIService::spi_cursor_close(ObPLExecCtx *ctx,
ObPLCursorInfo *cursor = nullptr;
ObObjParam cur_var;
ObCusorDeclareLoc loc;
uint64_t compat_version = 0;
bool null_value_for_closed_cursor = false;
CK (OB_NOT_NULL(ctx));
CK (OB_NOT_NULL(ctx->exec_ctx_));
CK (OB_NOT_NULL(ctx->exec_ctx_->get_my_session()));
@ -4180,23 +4178,8 @@ int ObSPIService::spi_cursor_close(ObPLExecCtx *ctx,
package_id, routine_id, cursor_index, cur_var);
OV (ignore || OB_ISNULL(cursor) || !cursor->is_invalid_cursor(), OB_ERR_INVALID_CURSOR, ignore, cur_var);
if (FAILEDx(ctx->exec_ctx_->get_my_session()->get_compatibility_version(compat_version))) {
LOG_WARN("failed to get compatibility version", K(ret));
} else if (OB_FAIL(ObCompatControl::check_feature_enable(
compat_version, ObCompatFeatureType::NULL_VALUE_FOR_CLOSED_CURSOR, null_value_for_closed_cursor))) {
LOG_WARN("failed to check feature enable", K(ret));
} else if (null_value_for_closed_cursor && OB_NOT_NULL(cursor) && cursor->is_session_cursor()) {
OZ (ctx->exec_ctx_->get_my_session()->close_cursor(cursor->get_id()));
OX (cur_var.set_obj_value(static_cast<uint64_t>(0))); // return closed refcursor as null
if (DECL_SUBPROG == loc) {
OZ (spi_set_subprogram_cursor_var(ctx, package_id, routine_id, cursor_index, cur_var));
} else if (DECL_LOCAL == loc) {
OX (cur_var.copy_value_or_obj(ctx->params_->at(cursor_index), true));
}
} else {
OZ (cursor_close_impl(ctx, cursor, cur_var.is_ref_cursor_type(), package_id, routine_id, ignore),
K(package_id), K(routine_id), K(cursor_index), K(cur_var));
}
OZ (cursor_close_impl(ctx, cursor, cur_var.is_ref_cursor_type(), package_id, routine_id, ignore),
package_id, routine_id, cursor_index, cur_var);
if (OB_SUCC(ret) && DECL_PKG == loc) {
OZ (spi_update_package_change_info(ctx, package_id, cursor_index));
}