flawopen.com/SQL Injection in Rust/sqlx
It validates that a parameterized query's shape matches your real database schema — it doesn't retroactively make an unparameterized, format!-built query safe.
let q = format!(
"SELECT * FROM users WHERE id = {}",
user_id
);
sqlx::query(&q).fetch_one(&pool).await?
sqlx::query!( "SELECT * FROM users WHERE id = ?", user_id ).fetch_one(&pool).await?
query! connects to your database at compile time (or uses a cached schema) to confirm the query is syntactically valid and its parameter/result types match your Rust types. This catches typos and schema drift — it has nothing to do with whether the query string was built safely in the first place. Building the string with format! before passing it to a non-macro query() call sidesteps the check entirely.
grep -rn "format!(" --include="*.rs" . | grep -B2 "sqlx::query"
Prefer it when possible — it gets you both the compile-time schema check and forces the parameterized form, closing off the format!-first mistake by construction.