Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Bind parameters given to Statement#execute persist beyond the call

Aperta
#751 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ruby, sqlite
Ambito
databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Ruby
Stelle
845
Fork
220
Merge medio
4g 6h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sparklemotion/sqlite3-ruby

Tutte le issue di sparklemotion/sqlite3-ruby

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.