Repository navigation
feat: Check text read into a character column with dbConnect(check_utf8 = TRUE) - #846
Conversation
…tf8 = TRUE)`
The new `check_utf8` argument of `dbConnect()` defaults to `getOption("RSQLite.check_utf8", FALSE)` and is kept with the connection.
With `check_utf8 = FALSE`, the default, every fetch behaves as before:
text with a NUL byte is cut silently, text that is not valid UTF-8 is returned marked as UTF-8,
and a blob in a character column is read as text, so that `X'00ff'` comes back as `""`.
With `check_utf8 = TRUE`, a text or blob value that is read into a character column is read with its byte length and validated.
A value that is not valid UTF-8, or that holds a NUL byte, becomes `NA`,
with one warning per column and fetch that counts the replaced values:
"Column `x`: 2 values are not valid UTF-8 or contain NUL bytes, NA is returned".
The fetch that returns a row raises this warning, a peek with `dbFetch(n = 0)` or `dbColumnInfo()` does not.
A blob is read with `sqlite3_column_blob()`, so it is not transcoded in a UTF-16 database and keeps its storage class after a peek.
Integer and real values in a character column, and blob columns, are read as before.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
Review of this pull request at 577784d, against its base fe9f927, by a Claude Code reviewer with clean context that read the description, the maintainer's request on #799, the two linked questions on #829, the diff What was run
What holds (Confirmed unless marked otherwise)
HighNone. MediumNone. LowL1. The default path makes an R string from every column name on every fetch. L2. No test checks that a value is read by its length. L3. L4. Any setting other than exactly L5. After merging with #795, the data frame path and the Arrow path will check differently. L6. The documentation and the description leave out a few behaviors. Generated by Claude Code |
…about `DbColumn::warn_invalid_strings()` took the column name as a `cpp11::r_string`, converted from the `std::string` that `DbDataFrame::get_data()` holds. Each column of each fetch therefore allocated a CHARSXP and a protected `cpp11::sexp`, also with `check_utf8 = FALSE`. It now takes a `const std::string&`, the UTF-8 bytes from `sqlite3_column_name()`, and builds nothing until it has something to warn about. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Values read from a table are followed by NUL bytes, so the existing tests also passed when a checked value was read up to its first NUL byte instead of by its length. The new test reads a bound blob, which has no NUL byte after it, into a character column. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
`dbConnect()` turned any `check_utf8` other than `TRUE` into `FALSE` with `isTRUE()`, so `"TRUE"`, `1`, `NA` or `c(TRUE, TRUE)` silently turned the checks off. This also applied to the `RSQLite.check_utf8` option, which is meant for code that opens connections indirectly and where a typo would go unnoticed. It now accepts only a single non-NA logical and otherwise fails with an error that names both the argument and the option. `extended_types` and `bigint` are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
In a UTF-16 database, a blob read into a character column is taken as UTF-8 bytes with the checks on, and transcoded from UTF-16 with them off. The checks apply to every query on the connection, including the ones RSQLite runs itself, so `dbListTables()` reports a table name that is not valid UTF-8 as `NA`. `dbConnect()` on an existing connection does not carry the setting over, nor `extended_types` or `bigint`, but reads the option again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Every test_that() block now runs on its own after load_all(). The six fixtures moved to tests/testthat/helper-check-utf8.R, each with a comment. with_warnings(), invalid_message(), local_check_con() and create_check_table() got a utf8 prefix, because helper names are shared by all test files: utf8_with_warnings(), utf8_invalid_message(), local_utf8_check_con() and create_utf8_check_table(). 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 clean review found nothing above Low. Its findings L1, L2, L4 and L6 are fixed: the column name is no longer converted to an R string on every fetch, so the default path is back to the cost of
Generated by Claude Code |
The CI's auto-update regenerated `src/cpp11.dd` and `src/utf8.dd` with GCC, whose dependency output indents continuation lines by one space, which the filter in `src/Makevars.deps` does not drop, so the files gained hundreds of absolute and vendored paths (#836). This restores them as they were and keeps the auto-update's formatting of `src/utf8.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The `RSQLite.check_utf8` option is dropped: `check_utf8` now defaults to `FALSE` and is set only by the argument. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Review of 6041aae in this pull request, by a Claude Code reviewer with clean context that read the one-commit diff, the pull request description, the clone method and the tests, built the commit in a detached worktree, ran the tests and an What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the current copy. The first clean review found nothing above Low; its findings L1, L2, L4 and L6 are fixed (ae50fc7, b805c2a, 448c8e1, a0e1409, 8fc168c). As decided, 6041aae makes
Generated by Claude Code |
Resolved: carry
|
Question: make the UTF-8 checks of the data-frame path and the Arrow path agree?The data-frame path checks text only when the connection was opened with
If nobody decides, the recommended option holds. Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the new copy. The first clean review found nothing above Low; its findings L1, L2, L4 and L6 are fixed (ae50fc7, b805c2a, 448c8e1, a0e1409, 8fc168c). As decided, 6041aae makes
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
Accepted limitationsThe first clean review found nothing above Low; its findings L1, L2, L4 and L6 are fixed (ae50fc7, b805c2a, 448c8e1, a0e1409, 8fc168c). As decided, 6041aae makes
Generated by Claude Code |
As asked on #799: checks of the text read into a character column, behind a
dbConnect()argument that defaults to the current behavior, on top of the UTF-8 infrastructure of #845. Unlike #799, which checked only blobs that turn up in a text column, this also checks text values, the more common case.The argument.
dbConnect()gainscheck_utf8, which defaults toFALSE, must beTRUEorFALSE(anything else stops with an error), and is kept with the connection. There is no R option: the maintainer decided on #829 for an argument only.check_utf8 = FALSE, the default. Every fetch runs the code ofmain: text with a NUL byte is cut silently, text that is not valid UTF-8 is returned marked as UTF-8, and a blob in a character column is read as text, soX'00ff'comes back as"". Three regression tests pin this, and they pass againstmaintoo.check_utf8 = TRUE. A text or blob value read into a character column is read with its byte length (sqlite3_column_text()orsqlite3_column_blob(), thensqlite3_column_bytes()) and validated. A value that is not valid UTF-8, or holds a NUL byte, becomesNA, with one warning per column and fetch that counts the replaced values: "Columnx: 2 values are not valid UTF-8 or contain NUL bytes, NA is returned". The fetch that returns a row raises the warning; a peek withdbFetch(n = 0)ordbColumnInfo()does not. A blob read withsqlite3_column_blob()is not transcoded in a UTF-16 database and keeps its storage class after a peek. Integer and real values in a character column, and blob columns, are read as before. The new warning passes its message as an argument, not as a printf format.Not changed here. The mixed-type warning still passes the column name inside its format, its text is not marked as UTF-8, and
fetch_blob()still hands a NULL pointer tomemcpy()for an empty blob; all three belong to the open question on format strings.dbConnect()on an existing connection does not carrycheck_utf8over here; #852, stacked on this pull request, makes a clone keep it, together withextended_typesandbigint. The checks apply to every query on the connection, including RSQLite's own, sodbListTables()reports a table name that is not valid UTF-8 asNA. The new warning, like the mixed-type warning, is not marked as UTF-8.Tests.
tests/testthat/test-check-utf8.Rcovers invalid text, text with a NUL byte, invalid and valid blobs, empty text and blobs, a fetch in chunks where a later chunk holds the bad values, a peek between chunks, a UTF-16 database, and a column name containing%s%d; undoing each part of the change makes them fail.R CMD check --no-manualwas rerun after dropping the option (only vignette and hidden-directory warnings of the local build tree), and the new and changed tests pass under AddressSanitizer and UBSan. Fetching 8 million strings takes as long as onmainwith the default, and 7% to 18% longer withcheck_utf8 = TRUE, depending on the data; many small fetches of wide results cost the same as onmain.A clean review found nothing above Low; four of its six findings are fixed, and what remains is under Accepted limitations. The tests' fixtures live in helper files, so every block runs on its own after
load_all().https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Generated by Claude Code