Bind parameters given to Statement#execute persist beyond the call
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sparklemotion/sqlite3-ruby
-
needs-more-info
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
sparklemotion/sqlite3-ruby#653 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
sparklemotion/sqlite3-ruby#639 · 4 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
sparklemotion/sqlite3-ruby#628 · 10 commenti · 1 reazione ·
-
bug help-wanted platform/windows
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
sparklemotion/sqlite3-ruby#618 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
sparklemotion/sqlite3-ruby#573 · 2 commenti ·
Tutte le issue di sparklemotion/sqlite3-ruby
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
iOS podspec depends on `React-Codegen`, which resolves to an unrelated pod on CocoaPods trunkAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
GantMan/jail-monkey#380 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
voxpupuli/puppet-wireguard#151 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug f:search
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno