go
data_error
ai_generated
true
错误:sql:期望0个参数,得到1个
error: sql: expected 0 arguments, got 1
ID: go/database-sql-prepare-query-error
80%修复率
84%置信度
0证据数
2026-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
向没有占位符的查询提供参数,或SQL语句中的占位符不匹配。
English
Providing arguments to a query that has no placeholders, or mismatched placeholders in the SQL statement.
解决方案
-
95% 成功率 Always use parameterized queries with correct placeholder count
query := "SELECT * FROM users WHERE id = ?" rows, err := db.QueryContext(ctx, query, userID)
无效尝试
常见但无效的做法:
-
Adding placeholders without verifying SQL
60% 失败
May introduce SQL injection risk; use parameterized queries correctly.