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 anErr
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()
}