From 880ca2e7867169b0b27e366b80cbd5a148bf053f Mon Sep 17 00:00:00 2001 From: LFC <990479+MichaelScofield@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:41:09 +0800 Subject: [PATCH] fix: return error to client if prepare stmt param not match (#2918) * fix: return error to client if prepare stmt param not match * Update src/servers/src/mysql/handler.rs Co-authored-by: Ruihang Xia --------- Co-authored-by: Ruihang Xia --- src/servers/src/mysql/handler.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/servers/src/mysql/handler.rs b/src/servers/src/mysql/handler.rs index 80a2964ca7..29ad263f22 100644 --- a/src/servers/src/mysql/handler.rs +++ b/src/servers/src/mysql/handler.rs @@ -26,6 +26,7 @@ use common_error::ext::ErrorExt; use common_query::Output; use common_telemetry::{error, logging, tracing, warn}; use datatypes::prelude::ConcreteDataType; +use itertools::Itertools; use opensrv_mysql::{ AsyncMysqlShim, Column, ErrorKind, InitWriter, ParamParser, ParamValue, QueryResultWriter, StatementMetaWriter, ValueInner, @@ -286,7 +287,27 @@ impl AsyncMysqlShim for MysqlInstanceShi } .fail(); } - let plan = replace_params_with_values(&plan, param_types, params)?; + + let plan = match replace_params_with_values(&plan, param_types, ¶ms) { + Ok(plan) => plan, + Err(e) => { + w.error( + ErrorKind::ER_TRUNCATED_WRONG_VALUE, + format!( + "err: {}, params: {}", + e.output_msg(), + params + .iter() + .map(|x| format!("({:?}, {:?})", x.value, x.coltype)) + .join(", ") + ) + .as_bytes(), + ) + .await?; + return Ok(()); + } + }; + logging::debug!("Mysql execute prepared plan: {}", plan.display_indent()); vec![ self.do_exec_plan(&sql_plan.query, plan, query_ctx.clone()) @@ -395,7 +416,7 @@ fn format_duration(duration: Duration) -> String { fn replace_params_with_values( plan: &LogicalPlan, param_types: HashMap>, - params: Vec, + params: &[ParamValue], ) -> Result { debug_assert_eq!(param_types.len(), params.len());