Repository navigation
fix: dbBind() fails when SQLite refuses to bind a value - #868
Conversation
The data-frame path of `dbBind()` ignored the return codes of `sqlite3_bind_text()`, `sqlite3_bind_blob()` and the other `sqlite3_bind_*()` calls, so a text or blob value over SQLite's length limit was bound as NULL without an error. Every return code is now checked, and a refused value fails with SQLite's message, naming the parameter and the row of the parameters. The failure marks the result complete, so that no fetch reads the reset statement and a following `dbBind()` starts afresh. The internal `connection_limit_length()` lowers `SQLITE_LIMIT_LENGTH` for the tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Review of this pull request at ddd58b0, by a Claude Code reviewer with clean context that read the description, the full diff against What was run
What holds
HighNone. Medium
Low
Generated by Claude Code |
`bind()` now clears `ready_` and the row count before binding the first row, so a refused value no longer leaves a result bound and fetched before reporting zero rows and the old row count. A fetch after such a failure errors as for an unbound result. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Second review round of this pull request, of af501a0, by a Claude Code reviewer with clean context that read the description, What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
`bind()` now also marks the result complete before binding the first row, so every failure there, including an unsupported parameter type, leaves the same completed, unbound state; a successful bind resets it in `init()`. The tests also check `dbHasCompleted()` and `dbGetRowsAffected()` after a failed re-bind, for a query and for a statement. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Superseded: Accepted limitationsSuperseded by the current copy. Two clean review rounds: the first of ddd58b0 found that a result bound and fetched before kept its state when the first row of a new
Generated by Claude Code |
Accepted limitationsTwo clean review rounds: the first of ddd58b0 found that a result bound and fetched before kept its state when the first row of a new
Generated by Claude Code |
`raise_bind_exception()` from #868 throws a `step_error` with SQLite's result code instead of calling `cpp11::stop()`, so that `read_ahead()` keeps a value SQLite refuses to bind like any other error of the step past the last row of a fetch. The completion it sets is held back until the next fetch raises the kept error, so that `dbHasCompleted()` stays `FALSE` until then. A new `dbBind()` resets both the state #868 resets and the kept error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
A value SQLite refuses to bind carries SQLite's own code since the merge of #868, such as `SQLITE_TOOBIG`; only a parameter of a type that cannot be bound carries `SQLITE_ERROR`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
…urce The checks of the bind return codes from #868 move into the parameter source: SqliteListParamSource checks each code through SqliteParamSource::check_bind(), which names the parameter and the row and throws a SqliteBindError with SQLite's code. The result's bind_row() turns it into a step_error with that code and marks the result complete, as raise_bind_exception() did, which goes away with the result's own row counter. The tests of both branches are kept in test-dbBind.R. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R
The tests from #868 pinned `dbHasCompleted()` as `TRUE` and `dbGetRowsAffected()` as `NA` after a failed `dbBind()`. This branch gives one state for every failed bind, as for an error from the statement: `dbHasCompleted()` returns `FALSE`, and `dbGetRowsAffected()` counts the rows changed since that bind, which is 0 when the first row fails to bind. `dbFetch()` still asks for a new bind. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Decided in #829 (comment).
On
main, the data-frame path ofdbBind()ignores the return codes ofsqlite3_bind_text(),sqlite3_bind_blob()and the othersqlite3_bind_*()calls inSqliteResultImpl::bind_parameter_pos(). A text or blob value over SQLite's length limit (SQLITE_LIMIT_LENGTH, 2147483647 bytes by default, lower if a connection sets it) is therefore bound as NULL without an error, and the row is written with NULL in its place. With RSQLite's build settings, the default limit (SQLITE_MAX_LENGTH=2147483647) equals R's maximum string length, so a value from R cannot exceed it; the check guards connections that lower the limit, and allocation failures (SQLITE_NOMEM).This pull request checks the return code of every
sqlite3_bind_*()call of that path. A refused value fails with SQLite's message, naming the parameter by position, by name for a named placeholder, and the row of the parameters, for exampleCan't bind parameter 2 (:x) in row 2: string or blob too big.The message is passed through a fixed format string.dbBind()now treats the result as unbound and completed until its first row is bound, so when the first row fails, a followingdbFetch()errors as for an unbound result instead of returning zero rows, anddbGetRowCount()no longer reports the previous binding's count. When a later row of the parameters fails, the result is marked complete, so no fetch reads the reset statement; the rows before it have already been executed, and rows already fetched in the samedbFetch()call are discarded with the error, as for an error fromsqlite3_step()in a later row onmain. In both cases a followingdbBind()with valid values binds afresh, anddbClearResult()works as before.#866 and #867 do the same on the Arrow path of
dbBindArrow(), with similar wording.For the tests, a new unexported entry point
connection_limit_length()setsSQLITE_LIMIT_LENGTHon a connection and returns the previous limit; it has the same signature as the one in the Arrow stack, so the two converge. SQLite does not go below 30 bytes, so the tests use that limit.Left out:
raise_sqlite_exception()still passessqlite3_errmsg()as the format string ofcpp11::stop(); that is fixed separately rather than here, to keep this change to the bind path. The other errors raised bybind_parameter_pos()(an unsupported parameter type) keep their message; in the first row they now leave the same completed, unbound result as a refused value, while in a later row they still do not mark the result complete.Tested with the new
tests/testthat/test-dbBind.R: text and blob values one byte over the limit fail, values at the limit bind and round-trip, a named parameter in a later row is named in the message, the result is complete after the failure and can be re-bound, a query bound and fetched before errors ondbFetch()after a failed re-bind, reports a row count of 0,dbHasCompleted()TRUE anddbGetRowsAffected()NA, a statement reportsdbGetRowsAffected()NA after a failed re-bind, an unsupported parameter type leaves a completed, unbound result,dbClearResult()succeeds after a failed bind, anddbExecute()with an over-long value fails and inserts nothing.devtools::test()withNOT_CRAN=true, DBItest included, passes except the three knowntest-httpvfs.Rerrors (#832, #837); the busy-handler test intest-dbConnect.Rruns against an installed build.https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Generated by Claude Code