Repository navigation
Conversation
A fetch of n rows steps once more to tell whether the result is complete. When that step fails, read_ahead() keeps the error, with SQLite's message and result code, and the next fetch raises it instead of the fetch losing its rows. A failed step or an unbindable parameter throws a step_error, which cpp11's entry points turn into the same R error as before. dbFetch(n = 0) and dbColumnInfo() leave a kept error alone, and a new dbBind() drops it. Ported from #850. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Question: Raise a refused parameter set from
|
The step past the last row of a fetch commits a write in autocommit mode, or runs the next parameter set. Keeping its error for a next fetch lost it when no fetch followed, as in `dbGetQuery(n = k)` or `dbClearResult()`, so that a failed commit went unnoticed. Statements that write now raise that error at once, as before; read-only statements keep it for the next fetch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The format-string test now goes through a write, so a read-only query covers the message kept for the next fetch. The NEWS bullet says that `dbHasCompleted()` stays `FALSE` after `dbFetch()` only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
What changes for users. A fetch steps one row past the last row it returns, to tell whether the result is complete and to finish the statement, which releases its read lock. For read-only queries, when that step fails,
dbGetQuery(n = k)anddbFetch(n = k)now return their k rows without an error where they failed before, and the next fetch raises the error, with SQLite's original message even if later statements on the connection failed in between. Until then,dbHasCompleted()isFALSE;dbFetch(n = 0)anddbColumnInfo()leave a kept error alone, and a newdbBind()drops it. Before, the fetch that held rows 1 to k raised the error of row k + 1 and those rows were lost; with several parameter sets, the error of a later set that fails to run or to bind was raised by the fetch that held the last row of the set before. For a read-only query, a value in a later parameter set that SQLite refuses to bind completes the result only once the next fetch has raised the refusal; a statement that writes raises it at once. An error among the rows a fetch asks for is still raised by that fetch, sodbGetQuery()never returns a result cut short.dbGetQuery(n = 4)over a read-only query whose fifth row fails returns four rows, asLIMIT 4would. Statements that write, such asINSERT ... RETURNING, still fail at once, as before: for them, the step past the last row may commit the write in autocommit mode or run the next parameter set, and an error kept there would be lost when no fetch follows, as withdbGetQuery(n = k)ordbClearResult(), so that a failed commit (a deferred foreign key,SQLITE_BUSY) or a failed later parameter set would go unnoticed.How. A failed step or an unbindable parameter throws a C++ exception,
step_error, that carries SQLite's message and result code, instead of callingcpp11::stop(), which signals the R error at once and could not be held back.read_ahead()catches it for the step past the last row of a full fetch and, ifsqlite3_stmt_readonly()says the statement doesn't write, keeps it; otherwise it rethrows it at once; the nextfetch_rows()raises it. Every otherstep_errorreaches R through cpp11's entry points, which turn it into the same R error as before, with the same message and condition call.raise_bind_exception()now takes SQLite's result code.Tests. New
tests/testthat/test-read-ahead.R(fixture inhelper-read-ahead.R) covers fetches of 1, 2 and 4 rows over a six-row result whose fifth row fails, several parameter sets including one that fails to bind and one SQLite refuses, a kept message surviving later failing statements,dbGetQuery(n = ), the column structure while an error is kept, a new bind dropping it, the statement releasing its lock after the last row, and statements that write raising at once: a deferred foreign key failing at commit withdbGetQuery(n = )and withdbFetch(n = k)followed bydbClearResult(),SQLITE_BUSYat commit with a second connection holding a read, and aCHECKfailing in a later parameter set. The format-string block now expects the error of its write case (INSERT ... RETURNING) from the first fetch, as statements that write raise at once; a separate read-only block checks that a kept message containing%is raised verbatim by the next fetch.test-out-of-memory.Rnow expects the row before an out-of-memory step to be returned. Red → green: on the base branch, 8 of the first 10 new blocks and the changed out-of-memory block fail (the other two pin existing behavior); the 3 blocks for statements that write pass on the base and failed (4 expectations) on this branch before writes were made to raise at once; with this change, the full suite withNOT_CRAN=truegives FAIL 0, WARN 3, SKIP 63, PASS 10803.Open points carried over from #850. For read-only queries,
dbGetQuery(n = )drops a later parameter set that SQLite refuses to bind, as it drops an SQLite error after the requested rows; #850 asked whether that should be raised instead, and recommended keeping it. For read-only queries,SQLITE_BUSYfrom the step past a fetch is kept like any other error, so a retry does not recover (#848); the result code a retry would need is kept with the error. What happens after the kept error is raised is left to later layers of the chain.Layer B1 of the rebuilt chain, planned in #880; based on #927. Ported from #850 (now a draft), which this pull request replaces; its squashed diff applies unchanged.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code