Skip to content

doc: bound parameters persist across executions - #760

Merged
flavorjones merged 1 commit into
mainfrom
card-793-document-sticky-bind-params
Oct 24, 2026
Merged

flavorjones merged 1 commit into
mainfrom
card-793-document-sticky-bind-params

Conversation

@flavorjones

@flavorjones flavorjones commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Motivation

Fixes #751.

As reported in #751, parameters passed to Statement#execute stay bound after the call, so a later #execute that omits a parameter reuses the earlier value:

stmt = db.prepare("select :a, :b")
stmt.execute(a: 1, b: 2).to_a  # => [[1, 2]]
stmt.execute(a: 3).to_a        # => [[3, 2]]

#execute binds through #bind_params (statement.rb), and SQLite keeps bindings until they are cleared. Changing this would break code that relies on it (see #757, now closed), so I am documenting it instead.

Details

The docs for Statement#execute, #execute!, #bind_param, #bind_params, #reset! and ResultSet#reset now say that bound values persist across executions. #execute and the FAQ show the example above, and point to Statement#clear_bindings! to set every parameter back to NULL. The FAQ also notes that the Database#execute family prepares a new statement for each call, so it is unaffected.

The #clear_bindings! description was a copy of the one for #reset!; it now says what the method does.

Parameters bound by `Statement#execute` stay bound, so a later `#execute`
that omits one reuses the earlier value. This was undocumented.

Document this on `Statement#execute`, `#execute!`, `#bind_param`,
`#bind_params`, `#reset!` and `ResultSet#reset`, and in the FAQ. Point
to `#clear_bindings!`, and fix its description, which was copied from
`#reset!`.

[Fix #751]
@flavorjones
flavorjones force-pushed the card-793-document-sticky-bind-params branch from 5b4198c to 0122a01 Compare October 24, 2026 16:12
@flavorjones
flavorjones enabled auto-merge (squash) October 24, 2026 16:20
@flavorjones
flavorjones disabled auto-merge October 24, 2026 16:29
@flavorjones
flavorjones merged commit e80ff06 into main Oct 24, 2026
131 of 136 checks passed
@flavorjones
flavorjones deleted the card-793-document-sticky-bind-params branch October 24, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bind parameters given to Statement#execute persist beyond the call

1 participant