Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return error to client if prepare stmt param not match #2918

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
MichaelScofield marked this conversation as resolved.
Show resolved Hide resolved
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: &Vec<ParamValue>,
MichaelScofield marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<LogicalPlan> {
debug_assert_eq!(param_types.len(), params.len());

Expand Down
Loading