You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bind parameters given to Statement#execute persist beyond the call #751
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:
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:
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.
After playing with this a bit, we could fix it, but I'm worried it will break code that relies on the current behavior. You're right that it comes from #execute calling #bind_params, and SQLite keeps bindings until they're cleared; I agree it's not at all obvious that #execute leaves parameters bound. Instead of changing it, I'll document it on #execute, #bind_params and ResultSet#reset, and point to Statement#clear_bindings! for anyone who wants a clean slate before each execution.
Activity
fix: Statement#execute binds its parameters for one execution
flavorjones commentedon Oct 24, 2026
After playing with this a bit, we could fix it, but I'm worried it will break code that relies on the current behavior. You're right that it comes from
#executecalling#bind_params, and SQLite keeps bindings until they're cleared; I agree it's not at all obvious that#executeleaves parameters bound. Instead of changing it, I'll document it on#execute,#bind_paramsandResultSet#reset, and point toStatement#clear_bindings!for anyone who wants a clean slate before each execution.doc: bound parameters persist across executions
flavorjones commentedon Oct 24, 2026
@jeremyevans FYI - documented this behavior in #760. Thanks for bringing it up!
doc: bound parameters persist across executions (sparklemotion#760)