Skip to content

MySQL query returns "(1835) Malformed communication packet." #3774

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

Open
Srlion opened this issue Mar 9, 2025 · 2 comments · May be fixed by #3857
Open

MySQL query returns "(1835) Malformed communication packet." #3774

Srlion opened this issue Mar 9, 2025 · 2 comments · May be fixed by #3857
Labels
bug db:mysql Related to MySQL E-easy good first issue Good for newcomers

Comments

@Srlion
Copy link

Srlion commented Mar 9, 2025

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

@Srlion Srlion added the bug label Mar 9, 2025
@abonander
Copy link
Collaborator

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:

@abonander abonander added db:mysql Related to MySQL E-easy good first issue Good for newcomers labels Mar 9, 2025
@esamattirs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug db:mysql Related to MySQL E-easy good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants