Repository navigation
Conversation
…RNING` A statement that writes and returns rows stopped on its first row in `dbBind()`, and `dbExecute()` never ran its later parameter sets, missed their errors and counted 0 changed rows, because SQLite counts the changes of such a statement when it finishes. `dbSendStatement()` now has its own method that marks the result: for a statement that writes, each execution runs to the end and drops the rows. Read-only statements, `dbSendQuery()` and `dbGetQuery()` keep their rows. An error in `dbExecute()` now names `dbSendStatement()`. Closes #946. 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
Member
Author
Question: should
|
…dropped rows `EXPLAIN` writes nothing although SQLite doesn't report it read-only, so it is no longer run to the end and `dbFetch()` returns its rows. A `PRAGMA` that writes and returns a row still runs to the end, which keeps `dbExecute()` right, and `dbFetch()` warns if rows were dropped and points to `dbSendQuery()`. The stepping loop checks for an interrupt every 1000 steps, which ends the execution like an error of a parameter set. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…ce about dropped rows The step past the last row of a fetch skips the parameter sets that return no row, and now checks for an interrupt every 1000 of them, as dbBind() does. The interrupt ends the fetch, unlike an SQLite error that is kept for the next one. The warning that `dbSendStatement()` discarded rows comes once per bind instead of on every `dbFetch()`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
This was referenced Dec 1, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dbExecute()now runs every parameter set of a statement that writes and returns rows, such asINSERT ... RETURNINGorUPDATE ... RETURNING, raises an error from any of them (classed asRSQLite_error_constraintetc.), and returns the number of changed rows instead of 0. The same holds fordbSendStatement()followed bydbBind()anddbGetRowsAffected().dbFetch()on such a result returns zero rows, the first time after each bind with a warning that the rows of a statement sent withdbSendStatement()were discarded and thatdbSendQuery()returns them; this also applies to aPRAGMAthat writes and returns a row, such asPRAGMA journal_mode = WAL(dbExecute()is unchanged for it,dbGetQuery()still returns the row).EXPLAINis never run to the end, sodbSendStatement()+dbFetch()returns its rows. A long run of parameter sets can now be interrupted, for any statement.dbGetQuery(),dbSendQuery()+dbFetch(), anddbSendStatement()with a read-only statement return their rows as before. An SQLite error indbExecute()now namesdbSendStatement()as its call instead ofdbSendQuery().Why:
dbBind()stepped such a statement until its first row and left the rest todbFetch(), whichdbExecute()never calls, so the later parameter sets never ran. SQLite also counts the changes of a statement only when it finishes, so even a single parameter set counted 0. Closes #946.How: RSQLite had no
dbSendStatement()method, so DBI's default sent statements throughdbSendQuery(). A new method passesis_statement = TRUEtoresult_create(). For a statement that SQLite does not report as read-only (sqlite3_stmt_readonly()),SqliteResultImpl::step()then keeps stepping past rows until the last parameter set is done, both indbBind()and right away for a statement without parameters. Errors go through the existing paths: a failed set leaves the result unbound with the changes since the bind counted (#936), and the condition is classed (#943).EXPLAIN(sqlite3_stmt_isexplain()) is left out too, since SQLite reports it as writing although it writes nothing; for aPRAGMAthat writes and returns a row there is no such test, so it runs to the end and the result remembers that it dropped rows, which the firstdbFetch()after the bind reports with a warning (only if rows were actually dropped). The stepping loop checks for an interrupt every 1000 steps withcpp11::check_user_interrupt(), which throws through the same catch blocks as an SQLite error: an interrupt indbBind()leaves the result unbound with the changes counted (#936), one indbFetch()completes it (#935). The read-ahead past the last row of a fetch, which skips parameter sets that return no row, checks for an interrupt the same way; an interrupt there ends the fetch instead of being kept for the next one like an SQLite error. Read-only statements are left out so thatdbSendStatement()+dbFetch()on aSELECTkeeps returning rows anddbExecute()on a largeSELECTdoesn't read it to the end; a question for the maintainer is whetherdbSendStatement()should run every statement to the end regardless.Tests: new
tests/testthat/test-returning.Rwith the reprex of #946 (all sets inserted or updated, counts 3 and 2, a constraint violation in a later set raised fromdbBind(), the state after a failed later set, a second bind counting its own changes) and pins fordbGetQuery(),dbSendQuery()+dbFetch()and a read-onlydbSendStatement(). Red on the base (10+ failures, counts 0, later sets missing, no error), green with the fix. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale), SKIP 63, PASS 11228 before the review follow-up, PASS 11257 after it. Review follow-up: tests forEXPLAINkeeping its rows,PRAGMA journal_modeviadbSendStatement()+dbFetch()(warning, zero rows),dbExecute()(sets WAL, returns 0) anddbGetQuery()(row returned), no warning when nothing was dropped, and a callr test that interruptsdbBind()of anINSERT ... RETURNINGwith 1e7 parameter sets and checks the state of a failed bind and a working rebind; theEXPLAIN, warning and interrupt tests fail on the previous head of this PR. Second review follow-up: a callr test that interrupts the read-ahead ofdbFetch(n = 2)over 1e7 parameter sets (red on the previous head: the interrupt isn't seen for over a minute and the fetch keeps its two rows; green: the result is completed with zero rows counted), and checks that the warning about discarded rows comes once per bind. Full suite after it: FAIL 0, WARN 3 (locale), SKIP 63, PASS 11270. Internal callers ofresult_create()in tests pass the new argument; the call expectation intest-conditions.Rchanges todbSendStatement.Layer B8 of the rebuilt chain, planned in #880; based on #945. New layer, not ported from an old PR.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code