Bind parameters given to Statement#execute persist beyond the call
还没有人认领这个 Issue。
评估
调研方向
Start from Statement#execute and bind_params, and run the two Ruby snippets in the issue to see the leftover state. Done means parameters passed to execute apply only to that call, while values set with bind_params still persist. The issue leaves the allocation trade-off open, so check with maintainers before choosing an approach.
由索引模型根据 Issue 内容生成。
描述
Discussed in https://github.com/sparklemotion/sqlite3-ruby/discussions/740
Originally posted by jeremyevans September 7, 2026
I found this behavior surprising. I'm not sure whether it is bug, since there is a simple implementation reason for it, but I don't know whether the behavior is expected or desired. Here's a simple example:
db = SQLite3::Database.new ":memory:"
stmt = db.prepare "SELECT :a + :b"
stmt.execute(a: 1, b: 2).to_a # => [[3]]
stmt.execute(a: 2).to_a # => [[4]]
stmt.execute(b: 3).to_a # => [[5]]
stmt.execute.to_a # => [[5]]
As you can see in the example, if you don't provide a bind parameter to execute, it uses the last bound value. I believe it works this way because execute calls bind_params if given any parameters, but it does not reset the preexisting bind parameter state after the statement executes.
You cannot reset the entire bind parameter state in execute, because this code is expected to work:
db = SQLite3::Database.new ":memory:"
stmt = db.prepare "SELECT :a + :b"
stmt.bind_params(a: 1)
stmt.execute(b: 2).to_a # => [[3]]
stmt.execute(b: 3).to_a # => [[4]]
My personal expectation would be that parameters given to execute only apply to that specific execution and not any subsequent executions. However, I realize that requires an allocation in the case where there are already bound parameters on the statement.
Note that this is only an issue when you have multiple execute calls on the statement, and a bind parameter set by one of the earlier execute calls is not set on a later one.
- 主要语言
- Ruby
- 星标
- 845
- 派生
- 220
- 平均合并
- 4 天 6 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sparklemotion/sqlite3-ruby 的其他 Issue
-
needs-more-info
难度 3/5 1-2 天 新手友好度 42/100
sparklemotion/sqlite3-ruby#653 · 3 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
sparklemotion/sqlite3-ruby#639 · 4 条评论 ·
-
难度 4/5 3-5 天 新手友好度 42/100
sparklemotion/sqlite3-ruby#628 · 10 条评论 · 1 个 reaction ·
-
bug help-wanted platform/windows
难度 4/5 3-5 天 新手友好度 35/100
sparklemotion/sqlite3-ruby#618 ·
-
难度 4/5 3-5 天 新手友好度 35/100
sparklemotion/sqlite3-ruby#573 · 2 条评论 ·
查看 sparklemotion/sqlite3-ruby 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
GantMan/jail-monkey#380 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
voxpupuli/puppet-wireguard#151 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug f:search
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复