MySQL query returns "(1835) Malformed communication packet."
I have found these related issues/pull requests
N/A
Description
Second query returns that error
(1835) Malformed communication packet.
It should return a MySQL error but it returns that message, it only happens if you supply no parameters when it expected parameters.
Reproduction steps
main.rs
use sqlx::mysql::MySqlConnection;
use sqlx::{Connection, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
let database_url = "";
let mut conn = MySqlConnection::connect(database_url).await?;
sqlx::query("CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, value TEXT);")
.execute(&mut conn)
.await?;
let res = sqlx::query("INSERT INTO`test_table`(`value`,`id`)VALUES('test',?)ON DUPLICATE KEY UPDATE`value`=VALUES(`value`);").execute(&mut conn).await;
println!("Query result: {:?}", res);
Ok(())
}
Cargo.toml
[package]
name = "sqlx-bug"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1.43.0", default-features = false, features = [
"rt-multi-thread",
"macros",
] }
anyhow = "1.0.96"
sqlx = { version = "0.8.3", features = [
"runtime-tokio",
"tls-native-tls",
"mysql",
"rust_decimal",
"chrono",
] }
SQLx version
0.8.3
Enabled SQLx features
"runtime-tokio", "tls-native-tls", "mysql", "rust_decimal", "chrono",
Database server and version
MySQL 8.0.4
Operating system
Windows
Rust version
rustc 1.84.1
This likely means we need to check that the number of arguments matches the number of parameters expected before we send the COM_STMT_EXECUTE:
- https://github.com/launchbadge/sqlx/blob/ca3a5090369238d156eb859d3fd699d86681f73f/sqlx-mysql/src/connection/executor.rs#L127
- https://github.com/launchbadge/sqlx/blob/ca3a5090369238d156eb859d3fd699d86681f73f/sqlx-mysql/src/connection/executor.rs#L141
It seems that this error is emitted in general when not enough parameters are provided, not just when no parameters are given. Error like Prepared statement expected X parameters but Y parameters where provided would be nice.