Repository navigation
Conversation
An SQLite error in `dbFetch()` or `dbGetQuery()` still raises at once, and the condition now carries the rows that the fetch read before the error in the field `rows`, as gh carries partial results in its conditions. The rows are converted as `dbFetch()` converts its result, for `bigint` and `row.names`, and count in `dbGetRowCount()`. The error kept from the step past the rows of the previous fetch carries zero rows. Errors while converting values and interrupts carry no rows. Closes #872. 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: how should an uncaught fetch error point users to the rows it carries?This pull request puts the rows read before an SQLite error into the condition's
Implemented on 2026-12-01: the recommended option is in 372f456; no box is ticked, and ticking another option changes it. If nobody decides, the recommended option goes in with the fixes of this pull request's review. Generated by Claude Code |
Building the rows of a failed fetch raises no warnings about their values, and the conversion in R muffles its warnings, so that a warning made an error or an exiting warning handler no longer replaces the SQLite error. `result_fetch()` returns the error with its rows to R, which raises it after the C++ frames have returned: raised through cpp11, the condition and its rows stayed referenced by cpp11's unwind token until the next error that unwound through it. The rows are taken over by the error without calling R's API outside of the unwind protection. The message adds a line that points to the `rows` field when the fetch read rows; SQLite's message stays in the `message` field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
The first error of a fetch in a fresh R process costs about 160k Vcells for compiling code, a large share of the threshold that varies across R versions. A failing fetch before the measurement leaves that cost out. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
An SQLite error in
dbFetch()ordbGetQuery()still raises at once, and its condition now carries the rows that the fetch read before the error in the fieldrows, instead of losing them. This mirrors gh, which hands the records it fetched before an interrupt to the caller in thegh_resultfield of the condition; the field here is namedrows, next to the unprefixedcode,extended_code,code_nameandextended_code_namethat #943 added. The rows are a data frame typed as that fetch would have returned it: the same column types, converted forbigintandrow.namesasdbFetch()converts its result. If that conversion fails, as withrow.names = "missing_column", the SQLite error is still raised and the field keeps the rows as RSQLite read them, so that no row is lost. Building and converting the rows of a failed fetch raises no warnings (such as "mixed type" or invalid UTF-8): withoptions(warn = 2)or an exitingwarning =handler, such a warning would otherwise replace the SQLite error and its rows. When the fetch read rows, the message adds a line such as "ℹ 4 rows read before the error are in the condition'srowsfield." (singular for one row); themessagefield stays SQLite's message, and errors without rows keep SQLite's message unchanged. The result is complete after the error, as before (#935).Which errors carry rows: every SQLite error that a fetch raises, that is, a failed step in the fetch loop (a malformed JSON value in a later row,
SQLITE_BUSY, a constraint in a later parameter set of aRETURNINGstatement), a later parameter set that SQLite refuses to bind, and the error of a writing statement's step past the last row of a full fetch, which is raised at once. The error kept from the step past the rows of the previous fetch (#933) is raised by the next fetch, which has read no row, so its field is a zero-row data frame with the columns of the result. Errors while converting values, warnings made errors, and interrupts are not SQLite conditions and carry no rows: their rows are lost as before. SQLite errors outside of a fetch (indbSendQuery(),dbBind(),dbExecute(),dbConnect()) have norowsfield.The rows in the condition count in
dbGetRowCount(): #935 counts rows "once they are returned", and the condition returns them to the caller. Before, the rows of a fetch that failed did not count, so this changes some of #935's expectations intest-fetch-error.R.Implementation: the fetch loop catches a
SqliteErrorof the step, leaves the loop, builds the data frame of the rows read so far inside the unwind protection and outside of any catch block, and throws aSqliteErrorthat takes it over by a move, which calls no R API.result_fetch()moves it out of the exception in the catch block and returns the error with its rows to R as a list of classRSQLite_fetch_error;check_fetch_error()in R raises it throughsignal_sqlite_error()insiderethrow(), which sets the call and converts the rows as before. Raised from C++ throughcpp11::function, the condition and its rows stayed referenced by cpp11's unwind token until the next error that unwound through it: with a 2M-row fetch, 24.6 MB stayed in use afterrm()andgc()instead of 9.4 MB; raised from R, it's 9.4 MB. Other SQLite errors are still raised from C++ bywith_sqlite_errors(). Nothing longjmps over C++ objects. The loop now advances the data frame before the step, so that the row before a failed step is part of it; the interrupt check moves before the step accordingly.The field is documented in
?"RSQLite-conditions", with an example that recovers the rows.Tested with a new
test-fetch-error-rows.R: rows of a plain query, ofdbGetQuery()with and without parameters, row names, all fourbigintsettings, the kept error with zero rows, a constraint in a later parameter set, no rows for conversion errors, and no field outside of a fetch; the info line in the message (plural, singular, none for zero rows), the SQLite error with its rows underoptions(warn = 2)and with an exitingwarning =handler, and that the rows are released once the handled condition is dropped (Vcells afterrm()andgc()). Red on the base (#943): the first six tests fail because the field isNULL; green here. The tests of the message, the warnings and the memory fail on the previous head of this pull request and pass now. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale), SKIP 63, PASS 11200.How an uncaught fetch error points to its rows was an open question (#945 (comment)); its recommended option is implemented: the info line in the message, raised with
stop()as before, without recording it forrlang::last_error(). Ticking another option there changes it.Closes #872.
Layer B2 of the rebuilt chain, planned in #880; based on #943. New code, not ported from an old PR; it follows the maintainer's decision in #880.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code