diff --git a/src/sql/engine/expr/ob_expr_to_outfile_row.cpp b/src/sql/engine/expr/ob_expr_to_outfile_row.cpp index 1615973fab..04a5e1648c 100644 --- a/src/sql/engine/expr/ob_expr_to_outfile_row.cpp +++ b/src/sql/engine/expr/ob_expr_to_outfile_row.cpp @@ -235,9 +235,9 @@ int ObExprToOutfileRow::print_field(char *buf, const int64_t buf_len, int64_t &p const bool need_enclose = 0 != out_info.wchar_enclose_ && (!out_info.is_optional_ || obj.is_string_type()); if (need_enclose) { - OZ(out_info.enclose_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_)); - } - if (0 == out_info.wchar_escape_) { + OZ(out_info.enclose_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_)); + } + if (0 == out_info.wchar_escape_) { OZ(obj.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_)); } else if (obj.is_null()) { OZ(out_info.escape_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_)); diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 3cfe7ae80e..c160a10066 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -5558,6 +5558,40 @@ int ObSPIService::collect_cells(ObNewRow &row, return ret; } +int ObSPIService::check_package_dest_and_deep_copy( + ObPLExecCtx &ctx, + const ObSqlExpression &expr, ObIArray &src_array, ObIArray &dst_array) +{ + int ret = OB_SUCCESS; + if (is_obj_access_expression(expr)) { + if (expr.get_expr_items().count() > 1 + && T_OP_GET_PACKAGE_VAR == expr.get_expr_items().at(1).get_item_type() + && OB_NOT_NULL(expr.get_expr_items().at(1).get_expr_operator()) + && expr.get_expr_items().at(1).get_expr_operator()->get_result_type().is_ext()) { + uint16_t param_pos = expr.get_expr_items().at(1).get_param_idx(); + uint64_t package_id = OB_INVALID_ID; + ObIAllocator *allocator = NULL; + OX (package_id = expr.get_expr_items().at(param_pos).get_obj().get_uint64()); + OZ (spi_get_package_allocator(&ctx, package_id, allocator)); + CK (OB_NOT_NULL(allocator)); + for (int64_t i = 0; OB_SUCC(ret) && i < src_array.count(); ++i) { + ObObj tmp; + if (src_array.at(i).is_pl_extend()) { + pl::ObUserDefinedType::deep_copy_obj(*allocator, src_array.at(i), tmp); + } else { + OZ (ob_write_obj(*allocator, src_array.at(i), tmp)); + } + OZ (dst_array.push_back(tmp)); + } + } else { + OZ (dst_array.assign(src_array)); + } + } else { + OZ (dst_array.assign(src_array)); + } + return ret; +} + int ObSPIService::store_result(ObPLExecCtx *ctx, const ObSqlExpression *result_expr, const ObDataType *result_types, @@ -5700,8 +5734,10 @@ int ObSPIService::store_result(ObPLExecCtx *ctx, ParamStore *params = ctx->params_; ObObjParam result_address; if (is_obj_access_expression(*result_expr)) { //通过ObjAccess访问得到的基础变量或record + ObSEArray dst_array; OZ (spi_calc_expr(ctx, result_expr, OB_INVALID_INDEX, &result_address)); - OZ (store_datums(result_address, *calc_array)); + OZ (check_package_dest_and_deep_copy(*ctx, *result_expr, *calc_array, dst_array)); + OZ (store_datums(result_address, dst_array)); } else if (is_question_mark_expression(*result_expr)) { //通过question mark访问得到的基础变量 int64_t param_idx = get_const_value(*result_expr).get_unknown(); ObAccuracy accuracy; @@ -5722,7 +5758,8 @@ int ObSPIService::store_result(ObPLExecCtx *ctx, OX (params->at(param_idx).set_accuracy(accuracy)); OZ (spi_pad_char_or_varchar(ctx->exec_ctx_->get_my_session(), result_types[0].get_obj_type(), accuracy, ctx->allocator_, &(params->at(param_idx)))); - } else if (is_get_var_func_expression(*result_expr) || is_get_package_or_subprogram_var_expression(*result_expr)) { + } else if (is_get_var_func_expression(*result_expr) + || is_get_package_or_subprogram_var_expression(*result_expr)) { //通过系统函数访问的基础变量(user var/sys var) 或 访问的package/subprogram 变量 ObObjParam value; OX (value = calc_array->at(0)); diff --git a/src/sql/ob_spi.h b/src/sql/ob_spi.h index 4eadb6da8f..4f7cfede20 100644 --- a/src/sql/ob_spi.h +++ b/src/sql/ob_spi.h @@ -793,6 +793,11 @@ private: const int64_t *pl_integer_ranges, bool is_bulk, int64_t limit); + + static int check_package_dest_and_deep_copy(pl::ObPLExecCtx &ctx, + const ObSqlExpression &expr, + ObIArray &src_array, + ObIArray &dst_array); }; }