Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Bind parameters given to Statement#execute persist beyond the call

未关闭
#751 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
ruby, sqlite
领域
databases

调研方向

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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sparklemotion/sqlite3-ruby 的其他 Issue

查看 sparklemotion/sqlite3-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。