You have en error in your SQL syntax ERROR 1064 (42000). MySQL crate

Hi! I'll be as short as I can. Your help would be really appreciated.
I'm new to the SQL and now I'm trying to add data in my table. I make 2 operations, the first one - I'm getting data from my table and then I add data there. I can get data, there are no errors. But when I'm trying to add it - this error occures

thread 'main' panicked at 'called Result::unwrap() on an Err value: MySqlError { ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':Type,:Month,:Income,:TaxIP,:Insurance,:CommunalPayment,:OtherNecessary)' at line 2 }', src/main.rs:121:7

I tried to add data with Strings some time before - everything worked just fine. But now I'm using f32 in my struct and my guesses are that there is some sort of special syntax when I try to pass it there. I don't know and I really need your help.

My code :

#[derive(Debug, PartialEq)]
struct ToWrite {
    typo : String,
    month : String,
    income : f32,
    taxIP : f32,
    insurance : f32,
    communalPayment : f32,
    otherNecessary : f32
}

fn send_data(connection : &mut PooledConn, object : ToWrite) -> () {
    let vector = vec![object];
    connection.exec_batch(r"INSERT INTO MySpents (Type, Month, Income, TaxIP, Insurance, CommunalPayment, OtherNecessary)
    VALUES (:Type,:Month,:Income,:TaxIP,:Insurance,:CommunalPayment,:OtherNecessary)",
    vector.iter().map(|object| params! {
        "Type" => &object.typo,
        "Month" => &object.month,
        "Income" => object.income,
        "TaxIP" => object.taxIP,
        "Insurance" => object.insurance,
        "CommunalPayment" => object.communalPayment,
        "OtherNecessary" => object.otherNecessary
    })
    ).unwrap()
}

I've solved it. That's the stupidest fix. I've just created a new table and changed all names to lowercase and it… Adds the data!.... I don't know how it works but it helped me. If someone faces it in the future try this method

#[derive(Debug, PartialEq)]
struct ToWrite {
    custom_type : String,
    month_chosen : String,
    income : f32,
    taxip : f32,
    insurance : f32,
    communal_payment : f32,
    other_pays : f32
}

fn send_data(connection : &mut PooledConn, object : ToWrite) -> () {
    let vector : Vec<ToWrite> = vec![object];
    let pr = connection.exec_batch(
        "INSERT INTO `my_income` (custom_type, month_chosen, income, taxip, insurance, communal_payment, other_pays)
        VALUES (:custom_type, :month_chosen, :income, :taxip, :insurance, :communal_payment, :other_pays)",
    vector.iter().map(|object| params! {
        "custom_type" => &object.custom_type,
        "month_chosen" => &object.month_chosen,
        "income" => object.income,
        "taxip" => object.taxip,
        "insurance" => object.insurance,
        "communal_payment" => object.communal_payment,
        "other_pays" => object.other_pays
    })
    );
    println!("{:#?}", pr)
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.