Skip to content

Commit

Permalink
fix: fix incorrect COM_STMT_PREPARE reply (#3463)
Browse files Browse the repository at this point in the history
* fix: fix incorrect `COM_STMT_PREPARE` reply

* chore: use column name instead of index
  • Loading branch information
WenyXu authored Mar 8, 2024
1 parent 3ee5336 commit a309cd0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
16 changes: 15 additions & 1 deletion src/servers/src/mysql/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,27 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for MysqlInstanceShi

debug_assert_eq!(params.len(), param_num - 1);

let columns = schema
.as_ref()
.map(|schema| {
schema
.column_schemas()
.iter()
.map(|column_schema| {
create_mysql_column(&column_schema.data_type, &column_schema.name)
})
.collect::<Result<Vec<_>>>()
})
.transpose()?
.unwrap_or_default();

let stmt_id = self.save_plan(SqlPlan {
query: query.to_string(),
plan,
schema,
});

w.reply(stmt_id, &params, &[]).await?;
w.reply(stmt_id, &params, &columns).await?;
crate::metrics::METRIC_MYSQL_PREPARED_COUNT
.with_label_values(&[query_ctx.get_db_string().as_str()])
.inc();
Expand Down
24 changes: 12 additions & 12 deletions tests-integration/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ pub async fn test_mysql_crud(store_type: StorageType) {
assert_eq!(rows.len(), 10);

for (i, row) in rows.iter().enumerate() {
let ret: i64 = row.get(0);
let d: NaiveDate = row.get(1);
let dt: DateTime<Utc> = row.get(2);
let bytes: Vec<u8> = row.get(3);
let ret: i64 = row.get("i");
let d: NaiveDate = row.get("d");
let dt: DateTime<Utc> = row.get("dt");
let bytes: Vec<u8> = row.get("b");
assert_eq!(ret, i as i64);
let expected_d = NaiveDate::from_yo_opt(2015, 100).unwrap();
assert_eq!(expected_d, d);
Expand All @@ -193,7 +193,7 @@ pub async fn test_mysql_crud(store_type: StorageType) {
assert_eq!(rows.len(), 1);

for row in rows {
let ret: i64 = row.get(0);
let ret: i64 = row.get("i");
assert_eq!(ret, 6);
}

Expand Down Expand Up @@ -358,9 +358,9 @@ pub async fn test_postgres_crud(store_type: StorageType) {
assert_eq!(rows.len(), 10);

for (i, row) in rows.iter().enumerate() {
let ret: i64 = row.get(0);
let d: NaiveDate = row.get(1);
let dt: NaiveDateTime = row.get(2);
let ret: i64 = row.get("i");
let d: NaiveDate = row.get("d");
let dt: NaiveDateTime = row.get("dt");

assert_eq!(ret, i as i64);

Expand All @@ -381,7 +381,7 @@ pub async fn test_postgres_crud(store_type: StorageType) {
assert_eq!(rows.len(), 1);

for row in rows {
let ret: i64 = row.get(0);
let ret: i64 = row.get("i");
assert_eq!(ret, 6);
}

Expand Down Expand Up @@ -709,13 +709,13 @@ pub async fn test_mysql_prepare_stmt_insert_timestamp(store_type: StorageType) {
.unwrap();
assert_eq!(rows.len(), 3);

let x: DateTime<Utc> = rows[0].get(1);
let x: DateTime<Utc> = rows[0].get("ts");
assert_eq!(x.to_string(), "2023-12-19 00:00:00 UTC");

let x: DateTime<Utc> = rows[1].get(1);
let x: DateTime<Utc> = rows[1].get("ts");
assert_eq!(x.to_string(), "2023-12-19 13:19:01 UTC");

let x: DateTime<Utc> = rows[2].get(1);
let x: DateTime<Utc> = rows[2].get("ts");
assert_eq!(x.to_string(), "2023-12-19 13:20:01.123 UTC");

let _ = server.shutdown().await;
Expand Down

0 comments on commit a309cd0

Please sign in to comment.