I've got the following piece of code which compiles:
pub fn add_user(&self, data: RegistrationForm) -> bool {
let mut conn = self.conn.get_conn().unwrap();
let execute_result = conn.exec_batch("
INSERT INTO users (
username, email, birthdate, password
) VALUES (
:username, :email, :birthdate, :password
)", params! {
"username" => &data.username,
"email" => data.email,
"birthdate" => data.birthdate,
"password" => data.password
});
match execute_result {
Ok(_) => {
println!("User {} added!", data.username);
true
}
Err(e) => {
eprintln!("Failed to add user {}: {}", data.username, e.to_string());
false
}
}
}
I'm sure that data.username
, data.email
, data.birthdate
, data.password
ain't empty. For some reason I get the following error at runtime;
Failed to add user test: DriverError { Statement takes 4 parameters but 2 was supplied }
I guess this has something to do with the prepared statement failing. But I don't see how it could fail?