From 69cfd4405efe29a187933d3f97ac9d9e10476b4a Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 1 Jan 2025 11:45:03 +0000 Subject: [PATCH] [to #2024122000106577236] fix assign null to refcursor --- src/sql/engine/expr/ob_expr_pl_get_cursor_attr.cpp | 14 +++++++++----- src/sql/ob_spi.cpp | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_pl_get_cursor_attr.cpp b/src/sql/engine/expr/ob_expr_pl_get_cursor_attr.cpp index 91830cafe..9c8cb9119 100644 --- a/src/sql/engine/expr/ob_expr_pl_get_cursor_attr.cpp +++ b/src/sql/engine/expr/ob_expr_pl_get_cursor_attr.cpp @@ -211,11 +211,15 @@ int ObExprPLGetCursorAttr::calc_pl_get_cursor_attr( if (info->pl_cursor_info_.is_explicit_cursor()) { CK (ObExtendType == datum_meta.type_); OX (datum->to_obj(obj, obj_meta)); - if (OB_SUCC(ret) - && obj.get_meta().get_extend_type() != pl::PL_CURSOR_TYPE - && obj.get_meta().get_extend_type() != pl::PL_REF_CURSOR_TYPE) { - ret = OB_ERR_CURSOR_ATTR_APPLY; - LOG_WARN("cursor attribute may not applied to non-cursor", K(ret), K(obj.get_meta())); + if (OB_SUCC(ret)) { + if (obj.is_null()) { + // do nothing, null cursor is legal... + } else if (!obj.is_ext() + || (obj.get_meta().get_extend_type() != pl::PL_CURSOR_TYPE + && obj.get_meta().get_extend_type() != pl::PL_REF_CURSOR_TYPE)) { + ret = OB_ERR_CURSOR_ATTR_APPLY; + LOG_WARN("cursor attribute may not applied to non-cursor", K(ret), K(obj.get_meta())); + } } OX (cursor = reinterpret_cast(obj.get_ext())); } else { diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index f7c7cf8c2..ccd2adc99 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -5864,13 +5864,14 @@ int ObSPIService::spi_copy_ref_cursor(ObPLExecCtx *ctx, // 到了这里先把returning状态重置,ref count先不加,等赋值成功再加 OX (src_cursor->set_is_returning(false)); } - if (src_cursor == dest_cursor) { + if (OB_FAIL(ret)) { + } else if (src_cursor == dest_cursor) { // 说明指向同一个内存,或者都为null, 这个时候应该不干,除了一个特殊的场景,即return场景,需要将count+1 // 例如: c1 := c2; c1 := c2; c2 may null or not null; if (need_inc_ref_cnt) { OX (src_cursor->inc_ref_count()); } - } else if (!src_cursor->isopen() && 0 == src_cursor->get_ref_count() && NULL == dest_cursor) { + } else if (OB_NOT_NULL(src_cursor) && !src_cursor->isopen() && 0 == src_cursor->get_ref_count() && NULL == dest_cursor) { // src cursor is already closed and do not has any ref // dest cursor is null do not need copy } else {