Fix print function bin/oct bug
This commit is contained in:
		
							
								
								
									
										3
									
								
								deps/oblib/src/common/object/ob_object.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								deps/oblib/src/common/object/ob_object.h
									
									
									
									
										vendored
									
									
								
							| @ -1106,8 +1106,7 @@ struct ObObjPrintParams | |||||||
|       uint32_t beginning_space_:1; |       uint32_t beginning_space_:1; | ||||||
|       uint32_t for_dblink_:1; |       uint32_t for_dblink_:1; | ||||||
|       uint32_t binary_string_print_hex_:1; |       uint32_t binary_string_print_hex_:1; | ||||||
|       uint32_t need_print_converter_:1; |       uint32_t reserved_:25; | ||||||
|       uint32_t reserved_:24; |  | ||||||
|     }; |     }; | ||||||
|   }; |   }; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -367,7 +367,6 @@ int ObVariableSetExecutor::calc_subquery_expr_value(ObExecContext &ctx, | |||||||
|       ObSqlString tmp_expr_subquery; |       ObSqlString tmp_expr_subquery; | ||||||
|       ObSqlString expr_subquery; |       ObSqlString expr_subquery; | ||||||
|       ObObjPrintParams print_params(session_info->get_timezone_info()); |       ObObjPrintParams print_params(session_info->get_timezone_info()); | ||||||
|       print_params.need_print_converter_ = false; |  | ||||||
|       ObRawExprPrinter expr_printer(expr_str_buf, OB_MAX_DEFAULT_VALUE_LENGTH, |       ObRawExprPrinter expr_printer(expr_str_buf, OB_MAX_DEFAULT_VALUE_LENGTH, | ||||||
|                                     &pos, ctx.get_sql_ctx()->schema_guard_, print_params); |                                     &pos, ctx.get_sql_ctx()->schema_guard_, print_params); | ||||||
|       if (OB_FAIL(expr_printer.do_print(expr, T_NONE_SCOPE, true, true))) { |       if (OB_FAIL(expr_printer.do_print(expr, T_NONE_SCOPE, true, true))) { | ||||||
|  | |||||||
| @ -3030,36 +3030,15 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr) | |||||||
|       case T_FUN_SYS_JSON_MERGE_PATCH: |       case T_FUN_SYS_JSON_MERGE_PATCH: | ||||||
|       case T_FUN_SYS_JSON_EXISTS: { |       case T_FUN_SYS_JSON_EXISTS: { | ||||||
|         if (lib::is_mysql_mode() && (expr_type == T_FUN_SYS_JSON_ARRAY || expr_type == T_FUN_SYS_JSON_MERGE_PATCH)) { |         if (lib::is_mysql_mode() && (expr_type == T_FUN_SYS_JSON_ARRAY || expr_type == T_FUN_SYS_JSON_MERGE_PATCH)) { | ||||||
|           DATA_PRINTF("%.*s(", LEN_AND_PTR(func_name)); |           DATA_PRINTF("%.*s", LEN_AND_PTR(func_name)); | ||||||
|                 int64_t i = 0; |           OZ(inner_print_fun_params(*expr)); | ||||||
|           for (; OB_SUCC(ret) && i < expr->get_param_count(); ++i) { |  | ||||||
|             PRINT_EXPR(expr->get_param_expr(i)); |  | ||||||
|             DATA_PRINTF(","); |  | ||||||
|           } |  | ||||||
|           if (OB_SUCC(ret)) { |  | ||||||
|             if (i > 0) { |  | ||||||
|               --*pos_; |  | ||||||
|             } |  | ||||||
|             DATA_PRINTF(")"); |  | ||||||
|           } |  | ||||||
|         } else if(lib::is_oracle_mode() || T_FUN_SYS_JSON_VALUE == expr_type) { |         } else if(lib::is_oracle_mode() || T_FUN_SYS_JSON_VALUE == expr_type) { | ||||||
|           if (OB_FAIL(print_json_expr(expr))) { |           if (OB_FAIL(print_json_expr(expr))) { | ||||||
|             LOG_WARN("fail to print json expr", K(ret), K(*expr)); |             LOG_WARN("fail to print json expr", K(ret), K(*expr)); | ||||||
|           } |           } | ||||||
|         } else { // mysql default |         } else { // mysql default | ||||||
|           DATA_PRINTF("%.*s(", LEN_AND_PTR(func_name)); |           DATA_PRINTF("%.*s", LEN_AND_PTR(func_name)); | ||||||
|           int64_t param_count = expr->get_param_count(); |           OZ(inner_print_fun_params(*expr)); | ||||||
|           int64_t i = 0; |  | ||||||
|           for (; OB_SUCC(ret) && i < param_count; ++i) { |  | ||||||
|             PRINT_EXPR(expr->get_param_expr(i)); |  | ||||||
|             DATA_PRINTF(","); |  | ||||||
|           } |  | ||||||
|           if (OB_SUCC(ret)) { |  | ||||||
|             if (i > 0) { |  | ||||||
|               --*pos_; |  | ||||||
|             } |  | ||||||
|             DATA_PRINTF(")"); |  | ||||||
|           } |  | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
| @ -3123,6 +3102,11 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr) | |||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|  |       case T_FUN_SYS_XML_EXTRACT: { | ||||||
|  |         DATA_PRINTF("extract"); | ||||||
|  |         OZ(inner_print_fun_params(*expr)); | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|       case T_FUN_ENUM_TO_STR: |       case T_FUN_ENUM_TO_STR: | ||||||
|       case T_FUN_SET_TO_STR: |       case T_FUN_SET_TO_STR: | ||||||
|       case T_FUN_ENUM_TO_INNER_TYPE: |       case T_FUN_ENUM_TO_INNER_TYPE: | ||||||
| @ -3135,44 +3119,16 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr) | |||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|       default: { |       case T_OP_CONV: { | ||||||
|         // substr |  | ||||||
|         // date, month |  | ||||||
|         // cur_date, current_date, cur_time, current_time |  | ||||||
|         // func_name |  | ||||||
|         if (T_FUN_SYS_ORA_DECODE == expr->get_expr_type()) { |  | ||||||
|           //同一个函数 在Oracle下名为decode, 在MySQL下名为ora_decode |  | ||||||
|           // for |  | ||||||
|           // 保证SQL反拼不会出错 |  | ||||||
|           if (lib::is_oracle_mode()) { |  | ||||||
|             func_name = "decode"; |  | ||||||
|           } else { |  | ||||||
|             func_name = "ora_decode"; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|         if (T_FUN_SYS_XML_EXTRACT == expr->get_expr_type()) { |  | ||||||
|           func_name = "extract"; |  | ||||||
|         } |  | ||||||
|         if (T_FUN_UDF == expr->get_expr_type()) { |  | ||||||
|           PRINT_QUOT; |  | ||||||
|           DATA_PRINTF("%.*s", LEN_AND_PTR(func_name)); |  | ||||||
|           PRINT_QUOT; |  | ||||||
|           DATA_PRINTF("("); |  | ||||||
|         } else { |  | ||||||
|         DATA_PRINTF("%.*s(", LEN_AND_PTR(func_name)); |         DATA_PRINTF("%.*s(", LEN_AND_PTR(func_name)); | ||||||
|         } |  | ||||||
|         if (OB_SUCC(ret)) { |  | ||||||
|         int64_t param_count = expr->get_param_count(); |         int64_t param_count = expr->get_param_count(); | ||||||
|         int64_t i = 0; |         int64_t i = 0; | ||||||
|         for (; OB_SUCC(ret) && i < param_count; ++i) { |         for (; OB_SUCC(ret) && i < param_count; ++i) { | ||||||
|           if (i == 0) { |           if (i == 0) { | ||||||
|             PRINT_EXPR(expr->get_param_expr(i)); |             PRINT_EXPR(expr->get_param_expr(i)); | ||||||
|             DATA_PRINTF(","); |             DATA_PRINTF(","); | ||||||
|             } else if (func_name.compare("BIN") == 0 || func_name.compare("OCT") == 0) { |           } else if (func_name.case_compare("BIN") == 0 || func_name.case_compare("OCT") == 0) { | ||||||
|               if (print_params_.need_print_converter_) { |             // do nothing | ||||||
|                 PRINT_EXPR(expr->get_param_expr(i)); |  | ||||||
|                 DATA_PRINTF(","); |  | ||||||
|               } |  | ||||||
|           } else { |           } else { | ||||||
|             PRINT_EXPR(expr->get_param_expr(i)); |             PRINT_EXPR(expr->get_param_expr(i)); | ||||||
|             DATA_PRINTF(","); |             DATA_PRINTF(","); | ||||||
| @ -3184,7 +3140,30 @@ int ObRawExprPrinter::print(ObSysFunRawExpr *expr) | |||||||
|           } |           } | ||||||
|           DATA_PRINTF(")"); |           DATA_PRINTF(")"); | ||||||
|         } |         } | ||||||
|  |         break; | ||||||
|       } |       } | ||||||
|  |       case T_FUN_SYS_ORA_DECODE: { | ||||||
|  |         //同一个函数 在Oracle下名为decode, 在MySQL下名为ora_decode | ||||||
|  |         // for | ||||||
|  |         // 保证SQL反拼不会出错 | ||||||
|  |         if (lib::is_oracle_mode()) { | ||||||
|  |           DATA_PRINTF("decode"); | ||||||
|  |         } else { | ||||||
|  |           DATA_PRINTF("ora_decode"); | ||||||
|  |         } | ||||||
|  |         OZ(inner_print_fun_params(*expr)); | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |       case T_FUN_UDF: { | ||||||
|  |         PRINT_QUOT; | ||||||
|  |         DATA_PRINTF("%.*s", LEN_AND_PTR(func_name)); | ||||||
|  |         PRINT_QUOT; | ||||||
|  |         OZ(inner_print_fun_params(*expr)); | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |       default: { | ||||||
|  |         DATA_PRINTF("%.*s", LEN_AND_PTR(func_name)); | ||||||
|  |         OZ(inner_print_fun_params(*expr)); | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 xianyu-w
					xianyu-w