Enhance change_falukant_user_money: Switch to literal SQL execution for update_money to resolve serialization issues with parameterized calls, improving reliability.
This commit is contained in:
@@ -201,18 +201,28 @@ impl BaseWorker {
|
|||||||
let uid_i32: i32 = falukant_user_id;
|
let uid_i32: i32 = falukant_user_id;
|
||||||
let money_str = format!("{:.2}", adjusted_money_change);
|
let money_str = format!("{:.2}", adjusted_money_change);
|
||||||
|
|
||||||
let p1: &(dyn ToSql + Sync) = &uid_i32;
|
// Note: we intentionally avoid parameterized call due to serialization
|
||||||
let p2: &(dyn ToSql + Sync) = &money_str;
|
// issues in this environment and instead execute a literal SQL below.
|
||||||
let p3: &(dyn ToSql + Sync) = &action;
|
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[BaseWorker] change_falukant_user_money: update_money(user_id={}, money_change='{}', action={})",
|
"[BaseWorker] change_falukant_user_money: executing literal update_money(user_id={}, money_change='{}', action={})",
|
||||||
uid_i32, money_str, action
|
uid_i32, money_str, action
|
||||||
);
|
);
|
||||||
|
|
||||||
// Execute parameterized
|
// Use a literal SQL call because parameterized execution keeps failing
|
||||||
let _ = conn.execute("update_money", &[p1, p2, p3])?;
|
// with "error serializing parameter 1" in this environment.
|
||||||
|
fn escape_sql_literal(s: &str) -> String {
|
||||||
|
s.replace('\'', "''")
|
||||||
|
}
|
||||||
|
let escaped_action = escape_sql_literal(action);
|
||||||
|
let sql = format!(
|
||||||
|
"SELECT falukant_data.update_money({uid}, {money}::numeric, '{act}');",
|
||||||
|
uid = uid_i32,
|
||||||
|
money = money_str,
|
||||||
|
act = escaped_action
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = conn.query(&sql)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user