Skip to content

fix: Keep names in default dbQuoteString() and dbQuoteLiteral() methods - #799

Merged
krlmlr merged 1 commit into
mainfrom
claude/quote-keep-names
Nov 29, 2026
Merged

krlmlr merged 1 commit into
mainfrom
claude/quote-keep-names

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

The default dbQuoteString() method now passes names(x) to SQL(), which paste() had dropped. The default dbQuoteLiteral() method keeps names in every branch: numeric and logical input (the names were lost by as.character() and as.numeric() before SQL(x, names = names(x)) read them), and factor, Date, POSIXt and difftime input, whose conversion to character is wrapped in a small keep_names() helper before the value is handed to dbQuoteString(). Character input goes through dbQuoteString() as before. NaN is still quoted as NaN, because the NA check still runs on the character result. Tests in tests/testthat/test-quoting.R cover every branch, unnamed input, and check that sqlInterpolate() and sqlAppendTable() produce the same SQL text for named input.

Closes #786.

DBItest spec. The specification DBI inherits (@inherit DBItest::spec_sql_quote_string / spec_sql_quote_literal, DBItest 1.9.0) says nothing about names for strings or literals. The return value is only required to be "an object that can be coerced to [character], of the same length as the input", and the tests compare with unname() (expect_identical(unlist(unname(x_out)), x) and expect_equal(as.list(unname(x_out)), x)). Only spec_sql_quote_identifier has a rule: "The names of the input argument are preserved in the output." This PR brings the two defaults in line with that rule for identifiers; extending the spec to strings and literals would be a separate DBItest change.

Downstream impact

Small. Only the default methods change, and only for named input; unnamed input produces identical objects. A clean review compared about 25 inputs between main and this branch and found the SQL text byte-identical for all of them. paste()/paste0(), as.character(), vapply(..., character(1)) and the show() method (which prints [email protected]) ignore names, so sqlInterpolate(), sqlAppendTable() and printing of SQL objects are unchanged. sqlData() runs on data frame columns, and data.frame() strips names from its columns, so its output is unchanged in the common case. What does change is names() of the result, and with it format(), c() and expect_identical()/snapshot comparisons of quoted named vectors. dbplyr 2.6.0 does not call dbQuoteString() or dbQuoteLiteral() (its escape() quotes with its own sql_quote()), so its translations are not affected. Backends that implement their own dbQuoteString() keep their own behavior; the default dbQuoteLiteral() now hands them named character input for factor, date and time values. A light code search found no downstream tests that compare quoted named vectors, but a reverse dependency check was not run.

Open question: revdep check, #799 (comment)

Accepted limitations: #799 (comment)

https://claude.ai/code/session_01Hr1rd3s7NRVkLyg3an422b


Generated by Claude Code

…ethods

The default methods now keep the names of atomic input,
as `dbQuoteIdentifier()` and the list (blob) branch of `dbQuoteLiteral()` already did.
The generated SQL text is unchanged.

Closes #786.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3s7NRVkLyg3an422b

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Run a reverse dependency check before merging?

The PR was merged on 2026-11-29 without a dedicated revdep check; the release checklist's revdep run covers it.

This PR changes only the names of the objects that the default dbQuoteString() and dbQuoteLiteral() methods return, and only for named input. The generated SQL text and the printed output stay the same, because paste(), as.character() and show() ignore names. That keeps sqlInterpolate(), sqlAppendTable() and sqlData() unchanged in practice. Only code that compares quoted named vectors with expect_identical() or snapshots, or that calls names(), format() or c() on them, would notice. A light GitHub code search found no such downstream test. dbplyr 2.6.0 does not call these methods; it quotes with its own sql_quote(). The DBItest 1.9.0 spec says nothing about names for strings and literals, and its tests compare after unname(). No revdep check has been run.

  • (recommended) No dedicated revdep check now. Rely on the revdep run that is part of the next release checklist, since the change is small and keeps the SQL text unchanged.
  • Dispatch revdep.yaml on this branch before merging. That covers all of the roughly 900 CRAN reverse dependencies, at the cost of a long run and a review of its results.
  • Run a targeted check on a few backends that inherit the default methods only.

If nobody decides, the PR waits as a draft until its review is through, and no revdep run is started.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review found nothing above Low. For each limitation it did find, the reviewer's assessment of relevance and confidence is given at the end of the item.


Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 11:09
@krlmlr
krlmlr merged commit 25e86e4 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/quote-keep-names branch November 29, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dbQuoteLiteral() and dbQuoteString() drop names for atomic input

2 participants