Update user money handling to prevent serialization errors: Adjusted the SQL query to cast money as numeric and modified the UserCharacterWorker to clamp and format the money value before executing the update. This change ensures valid numeric input and enhances error handling for user transactions.
This commit is contained in:
@@ -1171,7 +1171,7 @@ pub const QUERY_RANDOM_HEIR: &str = r#"
|
||||
|
||||
pub const QUERY_UPDATE_USER_MONEY: &str = r#"
|
||||
UPDATE falukant_data.falukant_user
|
||||
SET money = $1,
|
||||
SET money = $1::numeric,
|
||||
updated_at = NOW()
|
||||
WHERE id = $2;
|
||||
"#;
|
||||
|
||||
@@ -698,8 +698,16 @@ impl UserCharacterWorker {
|
||||
.get()
|
||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||
|
||||
let clamped = if !new_amount.is_finite() {
|
||||
1000.0
|
||||
} else {
|
||||
const MAX_ABS: f64 = 99_999_999.99;
|
||||
new_amount.clamp(-MAX_ABS, MAX_ABS)
|
||||
};
|
||||
let money_str = format!("{:.2}", clamped);
|
||||
|
||||
conn.prepare("update_user_money", QUERY_UPDATE_USER_MONEY)?;
|
||||
conn.execute("update_user_money", &[&new_amount, &falukant_user_id])?;
|
||||
conn.execute("update_user_money", &[&money_str, &falukant_user_id])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user