An SQL statement has a different number of placeholders than the values passed
What it finds
db.Query("SELECT * FROM t WHERE a = ? AND b = ?", a): the statement has two placeholders and the call passes one value, so the driver rejects the statement every time it runs. A value or a placeholder is missing.
Reported is a call of Query, QueryRow, Exec or their Context forms, in a file that imports database/sql, with a constant SQL statement and no args..., whose number of values differs from its placeholders: the ? outside quotes, or the highest $n. Statements that use both kinds are left alone.
From the rule's source, placeholder_count_mismatch.rs.
package p import "database/sql" func find(db *sql.DB, a, b int) { db.Query("SELECT * FROM t WHERE a = ? AND b = ?", a)tx0 reports: the statement has 2 placeholders but 1 values are passed db.Query("SELECT * FROM t WHERE a = $1 AND b = $2", a, b) db.Exec("UPDATE t SET a = $1 WHERE b = $3", a, b)tx0 reports: the statement has 3 placeholders but 2 values are passed db.Query("SELECT '?' FROM t WHERE a = ?", a)} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:placeholder-count-mismatch" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:placeholder-count-mismatch] reason="..."tx0 explain tx0/go:placeholder-count-mismatch shows the same in the terminal. Found a false positive? Report it.