Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

sqlite: excess bound parameters produce an opaque "column index out of range" error

未關閉
#65,163 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
冷清
技術堆疊
javascript, node.js, sqlite
領域
databases

研究方向

從 src/node_sqlite.cc 中的 StatementSync::BindParams 開始,閱讀現有的 param_count 處理邏輯和匿名 binding 迴圈。使用提供的 SQL 片段重現該問題;完成的標準是:多餘的匿名參數回報明確的參數數量錯誤,而不是 SQLite errcode 25,同時不改變現有的 binding 行為。

由索引模型根據 Issue 內容生成。

描述

sqlite
Version

v24.15.0 (also present on main)

Platform

Darwin 25.6.0 arm64 (platform-independent — pure BindParams logic)

Subsystem

sqlite

What steps will reproduce the bug?
const { DatabaseSync } = require('node:sqlite');
const db = new DatabaseSync(':memory:');
db.exec('CREATE TABLE t(a)');

const ins = db.prepare('INSERT INTO t VALUES (?)');
ins.run(1, 2);          // ERR_SQLITE_ERROR, errcode 25, "column index out of range"
db.prepare('SELECT 1').get(5);   // same

Any excess anonymous argument reproduces it, regardless of type — 2, 'x', and null all give the identical message.

How often does it reproduce? Is there a required condition?

Always, whenever the number of anonymous arguments exceeds the statement's sqlite3_bind_parameter_count().

What is the expected behavior? Why is that the expected behavior?

An error naming the actual problem — that more parameters were supplied than the statement accepts, ideally with both counts. Something like:

TypeError [ERR_INVALID_ARG_COUNT]: Statement accepts 1 parameter, but 2 were provided.

Two reasons this matters:

  1. The message describes the wrong thing. "Column index out of range" is SQLite's wording for a binding index, but to a JS caller "column" reads as a table column, pointing them at their schema rather than their call site. Nothing in the message indicates an argument-count mismatch.

  2. It's inconsistent with how the adjacent failure is reported. A wrong-type argument gets a precise Node-authored error: ERR_INVALID_ARG_TYPE: Provided value cannot be bound to SQLite parameter 2. A wrong-count argument falls through to a raw SQLite error code. Both are caller mistakes in the same call, caught in the same function.

What do you see instead?

ERR_SQLITE_ERROR with errcode: 25 and message column index out of range.

Additional information

The anonymous-binding loop in StatementSync::BindParams (src/node_sqlite.cc) iterates args from anon_start to args.Length() without comparing that span against sqlite3_bind_parameter_count(), so the overflow surfaces from sqlite3_bind_* instead. param_count is already fetched a few lines above, inside the bare-named-params block. A pre-loop guard would cover every excess-argument case at once.

Worth deciding up front whether this should throw at all, or ignore extra arguments the way ordinary JS functions do. Throwing seems better for a database API, and it's the current behavior, so a guard would preserve semantics while fixing only the message. Note this would be a breaking change for anyone matching on ERR_SQLITE_ERROR/errcode 25, so it likely wants semver-major treatment.

Surfaced while reviewing #62008, which changes undefined handling in the same function; the two are independent.

主要語言
JavaScript
星號
122k
分支
37.4k
平均合併
4 天 2 小時
30 天內合併 PR
277

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。