Skip to content

Commit

Permalink
fix: return error to client if prepare stmt param not match (#2918)
Browse files Browse the repository at this point in the history
* fix: return error to client if prepare stmt param not match

* Update src/servers/src/mysql/handler.rs

Co-authored-by: Ruihang Xia <waynestxia@gmail.com>

---------

Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
MichaelScofield and waynexia authored Dec 12, 2023
1 parent 0ce2b50 commit 880ca2e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/servers/src/mysql/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -286,7 +287,27 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for MysqlInstanceShi
}
.fail();
}
let plan = replace_params_with_values(&plan, param_types, params)?;

let plan = match replace_params_with_values(&plan, param_types, &params) {
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())
Expand Down Expand Up @@ -395,7 +416,7 @@ fn format_duration(duration: Duration) -> String {
fn replace_params_with_values(
plan: &LogicalPlan,
param_types: HashMap<String, Option<ConcreteDataType>>,
params: Vec<ParamValue>,
params: &[ParamValue],
) -> Result<LogicalPlan> {
debug_assert_eq!(param_types.len(), params.len());

Expand Down

0 comments on commit 880ca2e

Please sign in to comment.