Skip to content

fix: dbConnect() on a connection keeps bigint, extended_types and check_utf8 - #852

Open
krlmlr wants to merge 8 commits into
mainfrom
claude/clone-keeps-options
Open

krlmlr wants to merge 8 commits into
mainfrom
claude/clone-keeps-options

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Calling dbConnect() on an existing SQLiteConnection clones it, but the clone passed on only the database, the VFS, the flags and loadable.extensions, and ignored every argument given to dbConnect(con, ...). It dropped bigint and extended_types, so a clone of a connection opened with bigint = "character", extended_types = TRUE fell back to integer64 and to untyped dates and times. It also dropped check_utf8, added in #846, so a clone of a connection that checks text for valid UTF-8 did not check it.

Reproduced on main with a connection opened with bigint = "character", extended_types = TRUE on a table with a DATE column and the value 1099511627776:

  • the original returns d as Date and big as chr "1099511627776";
  • the clone returns d as chr "2020-01-02" and big as integer64, and clone@bigint is "integer64" and clone@extended_types is FALSE.

dbConnect_SQLiteConnection() now has explicit formals that mirror those of dbConnect_SQLiteDriver(), with the connection's dbname, loadable.extensions, flags, vfs, bigint, extended_types and check_utf8 slots as defaults, and passes every argument on to the driver method. So arguments to dbConnect(con, ...) are matched by name and by position as dbConnect(SQLite(), ...) would match them: dbConnect(con, bigint = "integer64"), dbConnect(con, extended_types = FALSE) and dbConnect(con, check_utf8 = FALSE) return what is asked, and dbConnect(con, other_path) opens other_path. The formals also show up in completion and in args(). A connection object saved by an older RSQLite, before the bigint, extended_types or check_utf8 slots existed, lacks those slots; for it, they fall back to the driver's defaults ("integer64", FALSE, FALSE) instead of failing with no slot of name. An argument that is NULL stays NULL, as in the driver: synchronous = NULL skips the pragma and dbname = NULL fails with the driver's error, length(dbname) == 1 is not TRUE (before this change, on main, a NULL dbname on a connection was not an error but opened a new temporary database). The error for cloning a temporary database remains, unless another dbname is given, and a misspelled dbname does not count as one. The documentation of drv, conn says what a clone keeps, and that a connection to a temporary database is only a template for another dbname: its settings carry over, its data does not. The note under check_utf8 that a clone does not keep it is removed.

Effects beyond reads, now consistent with the parent:

  • Writes: through a clone of an extended_types = TRUE parent, a Date column is created as DATE instead of REAL.
  • A clone of a bigint = "integer" parent now returns NA for values beyond 32 bits, like the parent, instead of integer64.
  • A clone of a check_utf8 = TRUE parent warns and returns NA for text that is not valid UTF-8, like the parent.

Accepted limitations, not changed here: default.extensions, synchronous and cache_size are not carried over (a parent opened with synchronous = "full" clones with "off", cache_size = 1234 becomes SQLite's default of -2000). flags, vfs and loadable.extensions were already kept. A wrapper that passes on a missing dbname now gets the driver's error.

Tests, in tests/testthat/test-dbConnect.R, each self-contained, thirteen new: a clone keeps bigint and extended_types and reads and types data accordingly; a clone keeps check_utf8 unless overridden; a clone of a default connection has the defaults; bigint and extended_types arguments override the parent; a second positional argument is the database; a connection to a temporary database can be used as a template for another dbname; NULL arguments are kept (synchronous = NULL, and dbname = NULL fails with the driver's message); a misspelled dbname does not clone a temporary database; a temporary database cannot be cloned otherwise; the formals match those of the driver method, with the same defaults except for the ones taken from the connection; with the driver method mocked, each formal and any extra argument reaches it unchanged; and each default comes from the matching slot of the connection (default.extensions from loadable.extensions); and a connection object without the bigint, extended_types and check_utf8 slots, as an old saved one looks, clones with the driver's defaults. Run against the base, ten of the thirteen fail and three pass (defaults, misspelled dbname, temporary cannot be cloned). Leaving check_utf8 out of the forwarding call, or taking the flags default from elsewhere, makes the mocked tests fail. test-dbConnect.R passes in full (24 tests, 85 expectations, with the package installed for the callr test). devtools::test() passes except the three known errors in test-httpvfs.R (#832, #837) and, without an installed build, the one test that starts a callr session.

The pull request sits on #846, which adds check_utf8. NEWS.md is maintained by fledge, so it is not edited. The fix comes from the old Arrow stack (01946d8 in #795); the plan to rework that stack splits it out as a separate pull request. Three review rounds (first, second, third) led to ff7fc0b, 43dd7e7 and 5ac4a57. The explicit formals, asked for after those rounds, had a clean review of their own at 68f541a that found nothing above Low; its fixes are d66dfdd (tests that every argument reaches the driver and every default comes from the connection) and 48ef91f (the fallback for missing slots); see the accepted limitations. Squash-merge, so that the commit messages of the fixes do not reach main.

https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ


Generated by Claude Code

krlmlr commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Review of this pull request at a0189d3, by a Claude Code reviewer with clean context that read the description, the diff against main at 3b7bea3, the connection code around the change (dbConnect_SQLiteDriver(), the SQLiteConnection class, sqliteRemote(), the C++ connect path) and the tests, built both commits into separate libraries, ran the changed tests, the full suite and its own reproducers on both, and posted nothing on GitHub itself.

What was run

  • R CMD INSTALL of a0189d3 and 3b7bea3 from detached worktrees under /home/user/wt/review-852/, each into its own library.
  • The PR's tests/testthat/test-dbConnect.R against both builds with testthat::test_file().
  • Each of the three new test_that() blocks alone in a fresh R session right after pkgload::load_all(), on both trees.
  • devtools::test() with NOT_CRAN=true on the PR, with R_LIBS pointing at the PR build so the callr test finds the package.
  • Two reproducer scripts on both builds: every dbConnect() argument on a parent with non-default values, PRAGMA synchronous and cache_size, default.extensions, the write side through dbDataType() and dbWriteTable(), explicit arguments to dbConnect(<connection>, ...), a read-only URI parent, a bigint = "integer" parent and a shared-cache memory URI.
  • No AddressSanitizer or valgrind: the change is R only. The PR's own CI run was still in progress and is not used here.

What holds

  • The fix passes exactly the two missing slots. On main a clone of a bigint = "character", extended_types = TRUE parent reads d as chr "2020-01-02" and big as integer64; on the PR it reads Date and chr "1099511627776", like the parent (Confirmed).
  • flags, vfs ("unix-dotfile"), loadable.extensions = FALSE and a read-only file:...?mode=ro dbname are carried over on both commits, as the description says (Confirmed).
  • The description is accurate about synchronous and cache_size being dropped (Confirmed, see Low 1).
  • The first new test fails on main with three failures and passes on the PR; the other two pass on both, as guards of existing behaviour; all three pass alone after load_all().
  • devtools::test() on the PR: 0 failures, only the three known test-httpvfs.R errors (test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837); the callr busy-handler test passes once the package is installed.
  • No C or C++ change, no src/*.dd change and no absolute paths in any .dd file; the scope matches the title. R CMD check was not needed, since no build file, DESCRIPTION, NAMESPACE or documentation is touched.

High

None.

Medium

  1. dbConnect(con, ...) still ignores every argument silently, and after this PR an explicit override yields the parent's value instead of the default.
    dbConnect_SQLiteConnection <- function(drv, ...) {
    if (drv@dbname %in% c("", ":memory:", "file::memory:")) {
    stop("Can't clone a temporary database", call. = FALSE)
    }
    dbConnect(SQLite(), drv@dbname,
    vfs = drv@vfs, flags = drv@flags,
    loadable.extensions = drv@loadable.extensions,
    bigint = drv@bigint, extended_types = drv@extended_types
    )
    }
    — With a parent opened with bigint = "character", extended_types = TRUE, each of dbConnect(con, bigint = "numeric"), bigint = "integer64", extended_types = FALSE, synchronous = "full" and flags = SQLITE_RO returns on main a clone with integer64, FALSE, flags 70 and synchronous 0, and on the PR one with character, TRUE, flags 70 and synchronous 0, with no warning on either (Confirmed). So dbConnect(con, bigint = "integer64") and dbConnect(con, extended_types = FALSE), which used to give what was asked by coincidence, no longer do, and dbConnect(con, other_path) opens a second connection to con's file instead of other_path on both commits (Confirmed). The function this PR edits is the one place where this would be decided, and the documentation (@param drv,conn: "the connection will be cloned") says nothing about what is kept. Suggested fix: build the argument list from the parent's slots and let named ... override it (utils::modifyList() and do.call()), stop on unnamed arguments, test one override, and say in @param drv,conn which settings a clone keeps; at the least, stop when ... is not empty.

Low

  1. synchronous and cache_size are still dropped, so a clone silently runs with synchronous = OFF even when the parent was opened with "full" or with NULL (SQLite's own default, FULL).

    if (!is.null(cache_size)) {
    cache_size <- as.integer(cache_size)
    tryCatch(
    dbExecute(conn, sprintf("PRAGMA cache_size=%d", cache_size)),
    error = function(e) {
    warning("Couldn't set cache size: ", conditionMessage(e), "\n",
    "Use `cache_size` = NULL to turn off this warning.",
    call. = FALSE
    )
    }
    )
    }
    if (!is.null(synchronous)) {
    synchronous <- match.arg(synchronous, c("off", "normal", "full"))
    tryCatch(
    dbExecute(conn, sprintf("PRAGMA synchronous=%s", synchronous)),
    error = function(e) {
    warning("Couldn't set synchronous mode: ", conditionMessage(e), "\n",
    "Use `synchronous` = NULL to turn off this warning.",
    call. = FALSE
    )
    }
    )
    }
    — Parent synchronous = "full": PRAGMA synchronous is 2, clone 0; parent synchronous = NULL: 2 versus 0; cache_size = 1234 becomes -2000; identical on both commits (Confirmed). The description says so and leaves it out, which is fair for this title, but the durability downgrade is worth a follow-up, and it needs no new slot: the clone can read both pragmas from the parent. Suggested fix: in a follow-up, pass cache_size = dbGetQuery(drv, "PRAGMA cache_size")[[1]] and map PRAGMA synchronous (0 to 3) onto synchronous, with EXTRA set by a PRAGMA after connecting; until then, document it next to the fix for Medium 1.

  2. default.extensions is not carried over either, and the description's list of other settings omits it.

    if (default.extensions) {
    initExtension(conn)
    }
    — For a parent opened with default.extensions = FALSE, SELECT reverse('abc') fails with "no such function" on the parent and returns "cba" on the clone, on both commits (Confirmed). Every sqliteRemote() connection is opened with default.extensions = FALSE (R/httpvfs.R), so its clones load the math extension. Mostly harmless, but nothing on the connection records it. Suggested fix: name it in the description among the settings that are not kept; carrying it would need a slot.

  3. The description covers reads only, but the fix also changes what a clone writes and, for integer and numeric parents, what it returns.

    dbConnect(SQLite(), drv@dbname,
    vfs = drv@vfs, flags = drv@flags,
    loadable.extensions = drv@loadable.extensions,
    bigint = drv@bigint, extended_types = drv@extended_types
    )
    — Through a clone of an extended_types = TRUE parent, dbDataType(clone, Sys.Date()) is "REAL" on main and "DATE" on the PR, so dbWriteTable() of a Date column creates d REAL on main and d DATE on the PR; a clone of a bigint = "integer" parent returned integer64 1099511627776 on main and returns NA without a warning on the PR, as the parent does (Confirmed). Both are the parent-consistent results, which DBI's "clone an existing connection" implies, and nothing in RSQLite, DBI or DBItest calls dbConnect() on a connection, so I see no reliance to protect. Suggested fix: add one sentence to the description and commit message saying that tables created through a clone and lossy bigint modes now follow the parent too, and assert dbDataType(clone, Sys.Date()) in the new test.

  4. The new test's expected data.frame() relies on R 4.0's stringsAsFactors = FALSE default, while DESCRIPTION declares R (>= 3.1.0).

    expect_identical(
    dbReadTable(clone, "t"),
    data.frame(d = as.Date("2020-01-02"), big = "1099511627776")
    )
    — On R 3.x big would be a factor and expect_identical() would fail (by reading). The oldest R in CI is 4.2, so it passes there, and the same file passes stringsAsFactors = FALSE at line 55. Suggested fix: add stringsAsFactors = FALSE.


Generated by Claude Code

krlmlr commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Review of the fixes in this pull request at ff7fc0b (the commits since a0189d3), by a Claude Code reviewer with clean context that read the description, the first review, the diff a0189d3..ff7fc0b with the rest of the pull request as context, the driver method the arguments are matched against and the DBI generic, built ff7fc0b and main at 3b7bea3 into separate libraries, ran the changed tests, the full suite, R CMD check and its own reproducers, and posted nothing on GitHub itself.

What was run

  • R CMD INSTALL of ff7fc0b and 3b7bea3 from detached worktrees, each into its own library.
  • The PR's tests/testthat/test-dbConnect.R against both builds with testthat::test_file(), and each of the six clone tests alone in a fresh session right after pkgload::load_all(), on both trees.
  • devtools::test() with NOT_CRAN=true on ff7fc0b, with the PR build on R_LIBS for the callr test.
  • R CMD build and R CMD check --no-manual of ff7fc0b, and roxygen2::roxygenise() (8.1.1.9000, as in DESCRIPTION) on its tree.
  • A reproducer of about 50 calls on both builds: dbConnect(<connection>, ...) with named, positional, partial and unknown names, NULL for each argument, expressions, a symbol value and an empty argument, every temporary parent with and without dbname, and the same arguments on dbConnect(SQLite(), ...) for comparison; then the same calls through a patched method to check the suggested fixes.
  • No sanitizer: the change is R only.

What holds

  • Named, positional and partial arguments override the parent as dbConnect(SQLite(), ...) would match them: bigint = "numeric", extended_types = FALSE, flags = SQLITE_RO (flags 1), synchronous = "normal" (1), cache_size = 100, db = other (partial, before ...) and a second positional argument all take effect, and the parent's vfs = "unix-dotfile", bigint and extended_types are kept otherwise (Confirmed). big = is not partially matched because it follows ..., and a third positional argument and unknown names are dropped silently, both exactly as in the driver.
  • Arguments are evaluated once, in the caller, by list(...), so expressions (dbname = paste0(other, "2")) and local variables work (Confirmed). Only a value that is itself a language object (bigint = quote(x)) is evaluated again by do.call(), which no formal here takes. The one input the driver accepts and the clone rejects is an empty argument (dbConnect(con, , bigint = "numeric"), "argument is missing"), which is not worth handling.
  • For "", ":memory:" and "file::memory:" parents, dbConnect(m) and dbConnect(m, bigint = "numeric") still raise "Can't clone a temporary database", and dbConnect(m, other) and dbConnect(m, dbname = other) open other; on main all of them raise the error (Confirmed).
  • All six clone tests pass alone after load_all(); on main the keep, override, positional and temporary-into-other tests fail and the other two pass, as the description says (Confirmed). Round 1's Low 3 and Low 4 are addressed.
  • devtools::test(): no failures, only the three known test-httpvfs.R errors (test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837). R CMD check --no-manual: tests OK, "dependencies in R code" and every Rd check OK, and one NOTE for a hidden .git file that comes from building in a worktree. utils is not in Imports, but main already calls utils::packageVersion() and utils::read.table() and check accepts it.
  • roxygenise() reproduces the committed man/SQLite.Rd and NAMESPACE without a diff, and the new @param drv,conn text matches the code except as in Medium 1. No C, C++ or src/*.dd change; the scope matches the title.

High

None.

Medium

  1. utils::modifyList() drops NULL arguments, so dbConnect(con, synchronous = NULL) runs the clone with synchronous = OFF instead of SQLite's default FULL, and other NULLs fall back to driver defaults instead of failing.
    defaults <- list(
    dbname = drv@dbname,
    vfs = drv@vfs, flags = drv@flags,
    loadable.extensions = drv@loadable.extensions,
    bigint = drv@bigint, extended_types = drv@extended_types
    )
    args <- utils::modifyList(defaults, args)
    do.call(dbConnect, c(list(SQLite()), args))
    — With synchronous = NULL, PRAGMA synchronous is 0 on the clone and 2 on dbConnect(SQLite(), path, synchronous = NULL) (Confirmed); NULL is the documented way to skip that pragma (R/dbConnect_SQLiteDriver.R#L137). dbname = NULL on a file parent opens a new temporary database where dbConnect(SQLite(), dbname = NULL) errors, and flags = NULL and loadable.extensions = NULL give flags 70 and TRUE where the driver errors (Confirmed). So the commit's "override them" holds for every value but NULL, and for synchronous the difference is durability. Suggested fix: args <- c(args, defaults[setdiff(names(defaults), names(args))]) instead of modifyList(), which keeps NULL and needs no utils (or modifyList(..., keep.null = TRUE)); through a patched method synchronous = NULL then gives 2 and dbname = NULL errors as in the driver, and the other probes are unchanged (Confirmed). Add a test that PRAGMA synchronous of dbConnect(con, synchronous = NULL) is 2L.

Low

  1. The temporary-database guard reads args$dbname, which matches partially, so a typo such as dbnames = path skips the error and returns a connection to a new, empty database.

    if (is.null(args$dbname) && drv@dbname %in% c("", ":memory:", "file::memory:")) {
    stop("Can't clone a temporary database", call. = FALSE)
    }
    — For a ":memory:" parent holding a table, dbConnect(m, dbnames = other) returns a :memory: connection without tables on ff7fc0b and "Can't clone a temporary database" on main (Confirmed): $ finds dbnames, which then goes to the driver's ... and is ignored. The error is therefore not raised exactly when no dbname is given. Suggested fix: is.null(args[["dbname"]]); the patched method errors again (Confirmed).

  2. The documentation does not say that a temporary database can be cloned only into another dbname.

    #' @param drv,conn An object generated by [SQLite()], or an existing \code{\linkS4class{SQLiteConnection}}.
    #' If a connection, the connection will be cloned:
    #' the new connection has the database, `vfs`, `flags`, `loadable.extensions`, `bigint` and `extended_types` of the original,
    #' unless they are passed as arguments to `dbConnect()`.
    #' `default.extensions`, `synchronous` and `cache_size` are not carried over.
    — The new @param drv,conn text lists what a clone keeps, but neither the error for "", ":memory:" and "file::memory:" nor the way past it that ff7fc0b adds (dbConnect(m, other) opens other with the parent's settings) is in the Rd (by reading). Suggested fix: add "A temporary database can't be cloned, unless dbname names another database." to @param drv,conn and regenerate.


Generated by Claude Code

krlmlr commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Review of the fixes in this pull request at 43dd7e7 (the commit since ff7fc0b), by a Claude Code reviewer with clean context that read the description, the second review, the diff ff7fc0b..43dd7e7 with the rest of the pull request as context and the driver method the arguments are passed to, built 43dd7e7, ff7fc0b and main at 3b7bea3 into separate libraries, ran the clone tests on all three, the full suite on 43dd7e7 and main, R CMD check and its own reproducers, and posted nothing on GitHub itself.

What was run

  • R CMD INSTALL of 43dd7e7, ff7fc0b and 3b7bea3 from detached worktrees, each into its own library.
  • Each of the eight clone blocks in tests/testthat/test-dbConnect.R alone in a fresh session right after pkgload::load_all(), on all three trees.
  • devtools::test() with NOT_CRAN=true and the matching build on R_LIBS (for the callr test): on 43dd7e7 and main with the default reporter; on 43dd7e7 again with a reporter that timestamps every file and test, once while R CMD check ran beside it (load average 8 on 4 cores) and once in a fresh worktree with no compiled objects.
  • roxygen2::roxygenise() (8.1.1.9000) on 43dd7e7, then R CMD build --no-build-vignettes and R CMD check --no-manual.
  • A reproducer, run on all three builds: 33 calls dbConnect(<file connection>, ...) on a parent with every carried setting away from its default, each next to the driver call with the parent's settings spelled out; they cover NULL and a value for each of dbname, loadable.extensions, default.extensions, cache_size, synchronous, flags, vfs, bigint and extended_types, all nine at once, partial names (db =, sync =), a partial value (bigint = "num"), a second, third and NULL positional argument, duplicates (bigint twice, db = with dbname =, foo twice) and unknown names. Then 11 calls on each of the "", ":memory:" and "file::memory:" parents. No sanitizer: the change is R only.

What holds

  • 32 of the 33 file-parent calls return the same connection settings, PRAGMA synchronous, cache_size and extension functions, or the same error, as the driver call (Confirmed). The one difference comes from my reference, which left out the parent's settings for dbConnect(con, db = a, dbname = b): both open b and pass db to ....
  • Every NULL now reaches the driver: synchronous = NULL gives PRAGMA synchronous 2 as the driver does (0 on ff7fc0b); dbname = NULL, a positional NULL and db = NULL fail with "length(dbname) == 1 is not TRUE" (a new temporary database on ff7fc0b); flags, loadable.extensions and default.extensions set to NULL fail as in the driver; vfs, bigint, extended_types and cache_size set to NULL give the driver's defaults, not the parent's (Confirmed).
  • No argument can reach the driver twice. match.call() places each formal once, and a duplicate fails with the driver's own "formal argument "bigint" matched by multiple actual arguments"; a ... entry cannot carry a formal's exact name; and the defaults fill only names not given. Partial names after ... (sync, big), a third positional argument, foo = NULL and duplicated foo reach ... and are ignored, as in the driver (Confirmed).
  • Temporary parents: no dbname, other arguments only, dbname = NULL, a positional NULL, dbnames = and dbName = all raise "Can't clone a temporary database" (ff7fc0b returned a new empty database for the misspellings); db =, a positional and a named dbname open the other database with the parent's bigint (Confirmed).
  • Alone after load_all(), all eight clone tests pass on 43dd7e7; on ff7fc0b the two new ones fail (two and one failures), so they catch the round-2 defects; on main five fail and three pass (Confirmed).
  • No run of the full suite hung. 43dd7e7: 1.0 min with the default reporter and 2.1 min under load, main 1.5 min, each with only the three known test-httpvfs.R errors (test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837), which fail in about a millisecond, before any HTTP request; PASS 10395 against 10378 on main. The slowest file is test-DBItest.R (103 s under load) and the slowest tests are the DBItest *_roundtrip_mixed ones at about 6 s each. In the fresh worktree, devtools::test() printed nothing after "Testing RSQLite" for 1.5 min while pkgload::load_all(quiet = TRUE) compiled sqlite3.c and the C++ sources, then ran the tests in 1 min. That silent compile, longer on a busier machine or with a cold ccache, is the likely explanation of the reported hang; the suite needs no test-httpvfs.R exclusion here.
  • roxygenise() reproduces man/SQLite.Rd and NAMESPACE without a diff. R CMD check --no-manual: tests OK and every Rd check OK; one NOTE for the .git file of the worktree and two vignette WARNINGs that come from building with --no-build-vignettes. No src change; the scope matches the title.

High

None.

Medium

None.

Low

  1. The description's test results are stale: the new NULL test fails on main too, and three tests pass there, not two.

    test_that("`NULL` arguments to `dbConnect()` on a connection are kept", {
    path <- tempfile()
    con <- dbConnect(SQLite(), path)
    on.exit(dbDisconnect(con), add = TRUE)
    fresh <- dbConnect(SQLite(), path, synchronous = NULL)
    on.exit(dbDisconnect(fresh), add = TRUE, after = FALSE)
    clone <- dbConnect(con, synchronous = NULL)
    on.exit(dbDisconnect(clone), add = TRUE, after = FALSE)
    expect_identical(
    dbGetQuery(clone, "PRAGMA synchronous")[[1]],
    dbGetQuery(fresh, "PRAGMA synchronous")[[1]]
    )
    expect_error(dbConnect(con, dbname = NULL))
    })
    test_that("a misspelled `dbname` does not clone a temporary database", {
    con <- dbConnect(SQLite(), ":memory:")
    on.exit(dbDisconnect(con), add = TRUE)
    expect_error(dbConnect(con, dbnames = tempfile()), "Can't clone a temporary database")
    })
    — The description says "On main the keep, override, positional and temporary-into-other tests fail; the other two pass on both", which was right for six tests. On main the NULL test fails as well (PRAGMA synchronous 0 against 2, and no error for dbname = NULL), and the defaults, misspelled and can't-be-cloned tests pass (Confirmed). Suggested fix: "On main the keep, override, positional, temporary-into-other and NULL tests fail and the other three pass; on ff7fc0b the NULL and misspelled tests fail."

  2. "A temporary database can be cloned only into another dbname" reads as if the temporary database were copied there.

    #' A temporary database can be cloned only into another `dbname`.
    — For a ":memory:" connection holding mtcars, dbConnect(m, other) creates other without any table; only the settings carry over (Confirmed). "Cloned into" is how copying a database is described, and RSQLite also has sqliteCopyDatabase() for that, so a reader can expect the data to follow. Suggested fix: "A connection to a temporary database can be cloned only with another dbname, and the new connection does not see the original's data." and regenerate the Rd.

  3. The commit message of 43dd7e7 says that on ff7fc0b dbname = NULL "fell back to the original database", but it opened a new temporary database. 43dd7e7 — On ff7fc0b, dbConnect(con, dbname = NULL) on a file connection returns a connection with dbname "" (Confirmed): modifyList() removed dbname from the defaults, so the driver's default applied. Suggested fix: if the commits are kept or their messages go into a squash, say "opened a new temporary database instead of failing as the driver does".


Generated by Claude Code

krlmlr commented Nov 12, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

Three review rounds: the first found that dbConnect(con, ...) ignored its arguments (Medium, fixed in ff7fc0b), the second that NULL arguments were dropped (Medium) and a misspelled dbname slipped past the temporary-database check (fixed in 43dd7e7), and the third nothing above Low; its wording and description points are fixed in 5ac4a57. In 33 calls on a parent with every setting changed, a clone now behaves like dbConnect(SQLite(), ...) with the same arguments. These remain:

  • R/dbConnect_SQLiteConnection.R#L13-L18: a clone inherits dbname, vfs, flags, loadable.extensions, bigint and extended_types, but not synchronous, cache_size or default.extensions, which the connection does not store; a clone of a connection opened with synchronous = "full" runs with the default "off" unless the argument is passed again, and a clone of an sqliteRemote() connection loads the default extensions. Reading them back with PRAGMA or storing them in new slots would be a change of its own. The help page says which settings carry over. Relevance: low; reviewer's confidence: high. (recorded)
  • 43dd7e77: its commit message says that before it dbname = NULL "fell back to the original database"; it opened a new temporary database. History is not rewritten; squash-merging replaces the message. Relevance: low; reviewer's confidence: high.

Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

Three review rounds: the first found that dbConnect(con, ...) ignored its arguments (Medium, fixed in ff7fc0b), the second that NULL arguments were dropped (Medium) and a misspelled dbname slipped past the temporary-database check (fixed in 43dd7e7), and the third nothing above Low; its wording and description points are fixed in 5ac4a57. In 33 calls on a parent with every setting changed, a clone now behaves like dbConnect(SQLite(), ...) with the same arguments. No limitation introduced by this pull request remains; this one is older:


Generated by Claude Code

Comment thread R/dbConnect_SQLiteConnection.R Resolved
@krlmlr

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Make this a stacked PR on top of #846, also copy over the newly introduced arg there.

@krlmlr
krlmlr changed the base branch from main to claude/utf8-text-checks November 13, 2026 15:25

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Re #852 (comment): this is now stacked on #846, and as of 68f541a a cloned connection keeps the original's check_utf8 unless it is passed to dbConnect(), with a test for both.


Generated by Claude Code

@krlmlr
krlmlr added this pull request to stack #847 November 13, 2026 15:31
@krlmlr krlmlr changed the title fix: dbConnect() on a connection keeps bigint and extended_types fix: dbConnect() on a connection keeps bigint, extended_types and check_utf8 Nov 13, 2026

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Question: treat a missing dbname as the connection's?

Since the explicit formals (68f541a), dbConnect_SQLiteConnection() passes dbname on to the driver as it receives it. A wrapper that forwards its own dbname without a value, such as f <- function(conn, dbname) dbConnect(conn, dbname), therefore fails on f(con) with argument "dbname" is missing, with no default, where the base ignored every argument and cloned con. The driver does the same: g <- function(dbname) dbConnect(SQLite(), dbname) fails on g() with the same error, so the clone now matches dbConnect(SQLite(), ...). A wrapper that checks missing(dbname) itself works. Reproducer, at 48ef91f with pkgload::load_all():

con <- dbConnect(SQLite(), tempfile(fileext = ".sqlite"))
f <- function(conn, dbname) dbConnect(conn, dbname)
f(con)
#> Error in f(con) : argument "dbname" is missing, with no default
g <- function(dbname) dbConnect(SQLite(), dbname)
g()
#> Error in g() : argument "dbname" is missing, with no default

The fix would be if (missing(dbname)) dbname <- drv@dbname at the top of the method, so that a forwarded missing dbname means the connection's database again. It would make the clone accept a call the driver rejects, and nothing in RSQLite, DBI or DBItest calls dbConnect() on a connection through such a wrapper.

  • Accept: keep the driver's behaviour; the description lists it among the accepted limitations (recommended)
  • Fix: treat a missing dbname as the connection's, with a test for the wrapper

If nobody decides, the limitation stays accepted and the pull request is merged as it is.


Generated by Claude Code

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

Four review rounds: the first found that dbConnect(con, ...) ignored its arguments (Medium, fixed in ff7fc0b), the second that NULL arguments were dropped (Medium) and a misspelled dbname slipped past the temporary-database check (fixed in 43dd7e7), and the third nothing above Low; its wording and description points are fixed in 5ac4a57. The explicit formals, asked for after those rounds, had a clean review of their own at 68f541a that found nothing above Low: tests that every argument reaches the driver and every default comes from the connection, and a pinned error message for dbname = NULL, are added in d66dfdd; a connection saved by an older RSQLite without the bigint, extended_types or check_utf8 slots, which failed with no slot of name, falls back to the driver's defaults since 48ef91f; the title and description are updated. This one remains:

  • R/dbConnect_SQLiteConnection.R#L7-L24: a wrapper that forwards a missing dbname, such as f <- function(conn, dbname) dbConnect(conn, dbname), fails on f(con) with argument "dbname" is missing, with no default, where the base cloned con; dbConnect(SQLite(), dbname) in the same wrapper fails the same way, so the clone matches the driver. See the question. Relevance: low; reviewer's confidence: high.

This one is older:


Generated by Claude Code

Base automatically changed from claude/utf8-text-checks to main November 13, 2026 19:45
`dbConnect()` on an existing connection passed on the database, the VFS, the flags and the extensions, but not `bigint` and `extended_types`.
The clone fell back to `integer64` and to untyped dates and times.
It now passes both on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The clone now takes the database, VFS, flags, extensions, `bigint` and `extended_types` of the original as defaults.
Arguments to `dbConnect(con, ...)` are matched against the driver method by name and by position and override them.
A temporary database can still not be cloned, unless another `dbname` is given.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
`modifyList()` dropped arguments that are `NULL`, so `synchronous = NULL` ran the clone with `synchronous = "off"`
and `dbname = NULL` fell back to the original database instead of failing as the driver does.
The defaults are now added only for the arguments that were not given.
The check for a temporary database reads `dbname` by exact name, so a misspelled `dbname` still errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A connection to a temporary database can only be used as a template
for a connection to another `dbname`:
its settings carry over, its data does not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
…ead of matching the call

`dbConnect_SQLiteConnection()` now has the formals of `dbConnect_SQLiteDriver()`, in the same order,
with the connection's own `dbname`, `vfs`, `flags`, `loadable.extensions`, `bigint`, `extended_types` and `check_utf8` as defaults.
It passes every argument by name to `dbConnect_SQLiteDriver()`,
so explicit `NULL` arguments and positional matching behave as before.
A test checks that the formals stay in step with the driver method.

A clone now also keeps `check_utf8` unless it is overridden,
and the documentation no longer says that it does not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
claude and others added 3 commits November 13, 2026 20:45
A mocked `dbConnect_SQLiteDriver()` records the arguments it receives,
so an argument added to the formals but left out of the forwarding call is caught,
as is a default that no longer comes from the connection.
The error for `dbname = NULL` is now pinned by its message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
A connection object saved before the `bigint`, `extended_types` or `check_utf8` slots existed
lacks them, so `dbConnect()` on it failed with "no slot of name".
The missing settings now fall back to the defaults of `dbConnect()` on the driver.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
@krlmlr
krlmlr force-pushed the claude/clone-keeps-options branch from 6739682 to 0d85a42 Compare November 13, 2026 19:45
@krlmlr krlmlr mentioned this pull request Nov 14, 2026
16 of 22 tasks

This branch has not been deployed

No deployments
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.

2 participants