Repository navigation
Conversation
`dbFetch()` steps one row past the last row it returns, to tell whether the result is complete and to finish the statement as soon as it is. When that step failed, the fetch raised the error and lost its rows, so the error of row k cost row k - 1 and every other row of that fetch. Now that fetch returns its rows, and the next `dbFetch()` raises the error, with SQLite's message saved when the step failed. This also holds when the step moves on to a later parameter set of `dbBind()` that fails to bind or to run. Until the error is raised, `dbHasCompleted()` returns `FALSE`, and `dbFetch(n = 0)` and `dbColumnInfo()` leave it for the next fetch that reads rows. A new `dbBind()` drops it. An error among the rows a fetch asks for is still raised by that fetch, so that `dbGetQuery()` never returns a result cut short. What happens after the error is raised is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
CI note: the smoke test failed before any R code ran, because the runners could not resolve the Ubuntu package mirrors while installing Generated by Claude Code |
|
Review of this pull request at 12b103a, by a Claude Code reviewer with clean context that read the description, the diff against What was run
What holds
HighNone. Medium1. The error path runs the opposite way to #795's, and the description gives no guidance for the merge. Low1. 2. A message with 3. Generated by Claude Code |
… intact A failed step, a kept error and a statement that fails to prepare now throw a C++ exception, which cpp11 turns into an R error at the entry point, instead of calling `cpp11::stop()` where they happen. The exception of a step carries SQLite's result code next to the message, and a kept error keeps both; a parameter that cannot be bound has `SQLITE_ERROR`. An SQLite message that contains a `%`, for example from a constraint name, now reaches R as it is: before, it was used as a format string and printed garbage or could crash. Otherwise the message, the class and the condition call (`NULL`) are the same as before. A calling handler of such an error now runs once the C++ frames of the call have unwound, rather than while they are still running. New tests pin that `dbGetQuery(n = )` drops an error after its rows, as `LIMIT` does, and that a kept error keeps its message after later statements on the connection fail. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Superseded: Accepted limitationsSuperseded by the current copy. The first clean review found one Medium and three Low issues, all fixed in 8be7cd8 apart from the retry below; the review of the fixes, run on the whole stack with #830 on top, found nothing above Low for this pull request, and its description's count of tests is corrected. These remain:
Generated by Claude Code |
Bring in #853 (gcc continuation lines in the generated `.dd` files) and #869 (no query text or SQLite message as a `printf()` format, `fetch_blob()` guarded against `NULL`). The conflict in `SqliteResultImpl::raise_sqlite_exception()` keeps this branch's `throw std::runtime_error(sqlite3_errmsg(conn))`: a failed prepare reaches R at cpp11's entry point like every other step error here, and cpp11 passes the message through `"%s"`, so it is not a format string either. The `.dd` files regenerated with the new `src/Makevars.deps` are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Superseded: Accepted limitationsSuperseded by the current copy. The first clean review found one Medium and three Low issues, all fixed in 8be7cd8 apart from the retry on
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
Question: Raise a refused parameter set from
|
Accepted limitationsThe first clean review found one Medium and three Low issues, all fixed in 8be7cd8 apart from the retry on
These are older:
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
Asked on #830: "Accuracy is important. Do we still need to fetch one row ahead? If yes, perhaps implement a transparent one-row cache in a fresh PR against
mainand stack this PR on top?" This is that pull request; #830 is stacked on it.Why the fetch loop reads ahead. Sending or binding a query steps once, which runs the statement; after that,
fetch_rows()reads the current row and then steps, so the statement always stands on the next row to return, and the last step of a fetch ofnrows goes one row past the rows it returns. DBI and DBItest do not require this:has_completed_query_spec_partialleavesdbHasCompleted()unspecified after fetching exactly all rows, and a version that steps lazily passes DBItest (658 tests) and RSQLite's own suite unchanged. The read-ahead still buys two things.dbHasCompleted()isTRUEright after the fetch that returns the last row, so the vignette'swhile (!dbHasCompleted(rs)) dbFetch(rs, n = 10)over 30 rows fetches 10, 10, 10 rather than 10, 10, 10, 0. More importantly, the step that reaches the end finishes the statement, which releases its read lock: without it, a reader that fetched exactly all its rows keeps the lock until the next fetch ordbClearResult(), and a write from another connection fails with "database is locked". So the read-ahead stays.What changes. When the step past the last row of a fetch fails, that fetch now returns all its rows, and the error is kept and raised by the next fetch; until then,
dbHasCompleted()isFALSE. Onmain, the fetch that held row k - 1 raised the error of row k and those rows were lost, or, with several parameter sets, the error of a later set that fails to bind or to run was raised by the fetch that held the last row of the set before.dbFetch(n = 0)anddbColumnInfo()leave a kept error alone, and a newdbBind()drops it. The same holds for a value in a later parameter set that SQLite refuses to bind, which completes the result since #868: when the read-ahead keeps that refusal,dbHasCompleted()staysFALSEuntil the next fetch raises it, and only then is the result complete (kept_error_completes_), with the row count of the rows returned. An error among the rows a fetch asks for is still raised by that fetch:dbGetQuery()sends, fetches withn = -1and clears, so holding that error back would silently return a result cut short. A failed step or an unbindable parameter now 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 so could not be held back; a kept error keeps both. The exception reaches R through cpp11's entry points, which turn it into the same R error as before, with the same message and condition call. An SQLite error message that contains%, such as the name of aCHECKconstraint, is no longer read as a printf format, also when a statement fails to prepare; two warnings that quote the query still are, as onmain.dbGetQuery(n = 4)over a result whose fifth row fails returns four rows, asLIMIT 4would, and the kept error goes with the cleared result. What happens after the kept error is raised is #830's business.Tests.
tests/testthat/test-read-ahead.R, with its fixture intests/testthat/helper-read-ahead.Rso that every block runs on its own afterload_all(): an SQLite message with%in it, through a fetch and through a kept error;dbGetQuery(n = ); a kept message that survives later failing statements on the connection; fetches of 1, 2 and 4 rows with row 5 failing; several parameter sets, including a third set that fails to bind; a value SQLite refuses to bind after a fetch, kept for the next fetch; the column structure staying available while an error is kept; a new bind dropping it; the statement finishing, and releasing its lock, after the last row; and an error among the asked-for rows. Eight of the ten blocks error onmain(53f2693); the other two pin behaviormainalready has.devtools::test()andR CMD check --no-manualpass apart from the HTTP VFS errors that #832 is about, and the read-ahead and query tests run clean under AddressSanitizer and UBSan.Merging into #795. #795 already throws from
raise_sqlite_exception()so that the fetch loop can run inside an Arrow stream callback, which this pull request now matches. The resolution of a trial merge of this stack into #795 is in #830's description.A clean review found one Medium finding, the error path running the opposite way to #795's, and three Low ones; all are fixed in 8be7cd8 except the retry on
SQLITE_BUSY, which #848 tracks. A review of the fixes, with #830 on top, found nothing above Low for this pull request. A clean review of the merge ofmainwith #868 found one Medium issue thatmainalready has, now in #838, and three Low ones: the comment onstep_error's result code is fixed in c029a2c, this description now covers the merge, anddbGetQuery(n = )dropping a refused parameter set is up for a question. What remains is under Accepted limitations.Coordinating session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
Generated by Claude Code