Bind parameters given to Statement#execute persist beyond the call
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Ruby
- Estrelas
- 845
- Forks
- 220
- Merge médio
- 4d 6h
- PRs com merge (30d)
- 8
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de sparklemotion/sqlite3-ruby
-
needs-more-info
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
sparklemotion/sqlite3-ruby#653 · 3 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
sparklemotion/sqlite3-ruby#639 · 4 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 42/100
sparklemotion/sqlite3-ruby#628 · 10 comentários · 1 reação ·
-
bug help-wanted platform/windows
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
sparklemotion/sqlite3-ruby#618 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
sparklemotion/sqlite3-ruby#573 · 2 comentários ·
Todas as issues de sparklemotion/sqlite3-ruby
Issues semelhantes
-
NoMethodError in auth#createAbertabugsnag
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
JoeMcB/improvcoaches#827 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
TheOdinProject/curriculum#31465 ·
Mantenedores costumam responder em até 1 dia
-
area: docs eco: ruby good first issue help wanted lane: free-agent roadmap size: XS type: docs
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 66/100
arminazimi/evergreen#465 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
simp/puppetsync#120 ·
Mantenedores costumam responder em até 2 dias